java - 安卓。如何更改选项卡文本颜色?

标签 java android colors styles textcolor

我想将选项卡文本的颜色设置为白色,我找不到任何好的教程。有人能帮我吗?

这是我的选项卡 Activity :

package com.example.dev.nordugrid;

import android.app.TabActivity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.TabHost.TabSpec;  
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@SuppressWarnings("deprecation")
public class Busena extends TabActivity {
SharedPreferences prefs;

TextView proxySuteike, proxyGaliojimas;
Button button4;
public int randomInt;
String stringProxyGaliojimas, stringProxySuteike, stringUzduotiesPav, stringUzduotiesJDL, stringKitiFailai;

Button holder;
private ArrayList<Item> m_parts = new ArrayList<Item>();
private Runnable viewParts;
private ItemAdapter m_adapter;

private final String data[] = { "Android", "iPhone", "BlackBerry", "AndroidPeople" };
private final String data2[] = { "Ivykdyta", "Atsaukta", "Einama", "Nusisnekejo" };
List<String> a = new ArrayList<String>();
List<String> b = new ArrayList<String>();


public static void setDefaults(String key, String value, Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putString(key, value);
    editor.commit();
}
public static String getDefaults(String key, Context context) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    return preferences.getString(key, null);
}
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.setContentView(R.layout.activity_busena);
    this.setTheme(R.style.listItem);
    holder = (Button)findViewById(R.id.button19);



    proxyGaliojimas = (TextView)findViewById(R.id.generatenumber);
    proxySuteike = (TextView) findViewById(R.id.textView5);

    randomInt = Integer.parseInt(getDefaults("proxy", this));
    stringProxySuteike = getDefaults("vo", this);

    proxyGaliojimas.setText(randomInt + " min.");
    proxySuteike.setText(stringProxySuteike);

    stringUzduotiesPav = getDefaults("uzduotiesPav", this);
    stringUzduotiesJDL = getDefaults("jdlFailoReiksme", this);
    stringKitiFailai = getDefaults("kitiFailaiReiksme", this);


    ListView list   = (ListView)findViewById(R.id.tab1);


    m_parts.add(new Item(stringUzduotiesPav, stringUzduotiesJDL));


    m_adapter = new ItemAdapter(this, R.layout.row, m_parts);
    list.setAdapter(m_adapter);

    button4 = (Button) findViewById(R.id.refreshProxy);
    TabHost tabHost = getTabHost();
    this.setNewTab(this, tabHost, "tab1", R.string.uzduotys, android.R.drawable.star_on, R.id.tab1);
    this.setNewTab(this, tabHost, "tab2", R.string.proxy, android.R.drawable.star_on, R.id.tab2);

    addListenerOnButton();

}


/*@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    String item = (String) getListAdapter().getItem(position);
    Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show();
}*/

private void setNewTab(Context context, TabHost tabHost, String tag, int title, int icon, int contentID ) {
    TabSpec tabSpec = tabHost.newTabSpec(tag);
    String titleString = getString(title);
    tabSpec.setIndicator(titleString, context.getResources().getDrawable(android.R.drawable.star_on));
    tabSpec.setContent(contentID);
    tabHost.addTab(tabSpec);
}

public void addListenerOnButton() {
    button4.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int skaicius = randomInt;
            Random randomGenerator = new Random();
            int rand = randomGenerator.nextInt(240-skaicius);
            String ats = Integer.toString(randomInt);
            proxyGaliojimas.setText(ats + " min.");
            randomInt = rand;
        }

    });
}
}

这就是我所看到的:

enter image description here

这是选项卡 Activity xml 文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.dev.nordugrid.Busena"
android:background="@drawable/background"
>
<TabHost
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    >
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">
        <TabWidget
            android:theme="@style/listItem"
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"></TabWidget>
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <ListView
                android:id="@+id/tab1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical" />
                <LinearLayout
                    android:id="@+id/tab2"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:orientation="vertical">
                    <!-- antro tabo vaizdas -->
                    <TextView
                        android:layout_marginTop="3dp"
                        android:id="@+id/textView3"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/proxyGaliojimas"
                        android:textColor="#FFFBFB"
                        android:textAppearance="?android:attr/textAppearanceMedium" />
                    <TextView
                        android:layout_marginLeft="7dp"
                        android:layout_marginTop="3dp"
                        android:id="@+id/generatenumber"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/min"
                        android:textColor="#FFFBFB"
                        android:textAppearance="?android:attr/textAppearanceMedium" />
                    <TextView
                        android:layout_marginTop="3dp"
                        android:id="@+id/textView4"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/proxySuteike"
                        android:textColor="#FFFBFB"
                        android:textAppearance="?android:attr/textAppearanceMedium" />

                    <TextView
                        android:layout_marginLeft="7dp"
                        android:layout_marginTop="3dp"
                        android:id="@+id/textView5"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/proxySuteike"
                        android:textColor="#FFFBFB"
                        android:textAppearance="?android:attr/textAppearanceMedium" />

                    <Button
                        android:layout_marginTop="7dp"
                        android:id="@+id/refreshProxy"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/atnaujinti"
                        android:textColor="#FFFBFB"
                        android:background="@drawable/border"/>
                    </LinearLayout>
        </FrameLayout>
    </LinearLayout>
</TabHost>

请有人给我简单的例子或其他帮助:)

最佳答案

创建此方法:-

private static View createTabView(Context context, String tabText) {
    View view = LayoutInflater.from(context).inflate(R.layout.custom_tab, null, false);
    TextView tv = (TextView) view.findViewById(R.id.tabTitleText);
    tv.setText(tabText);
    return view;
}
<小时/>

在布局文件夹中创建custom_tab.xml文件

    <?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/tabTitleText"
          android:layout_width="@dimen/tabWidth"
          android:layout_height="wrap_content"
          android:gravity="center_horizontal"
          android:clickable="true"
          android:paddingTop="@dimen/tabTopPading"
          android:paddingBottom="@dimen/tabBottomPading"
          android:paddingLeft="@dimen/tabLeftPading"
          android:paddingRight="@dimen/tabRightPading"
          android:textSize="@dimen/tabTextSize"
          android:textColor="@color/themeColor"
          android:background="@drawable/tab_selector"/>
<小时/>

终于确定了

tabHost.newTabSpec("Tab1").setIndicator(createTabView(getApplicationContext(),"Tab_name"))

关于java - 安卓。如何更改选项卡文本颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29988717/

相关文章:

javascript - highcharts.js - 动态标签颜色

java - 如何在 Swing 应用程序中从 Logback 链接日志?

java - Eclipse 中的 exec-maven-plugin :1. 2.1

javascript - Vert.x 的 POST 请求和 JavaScript 有什么区别?

java - 为什么这个与选择字段绑定(bind)的 Thymeleaf 表单不起作用?

r - scale_color_manual 颜色不会改变

android - 删除了 Facebook SDK,仍然显示在 AndroidManifest 中

java - 在布局底部创建一个三角形

java - 可以将 List<Class> 上传到 firebase 实时数据库

c# - 如何将 System.Drawing.Color 转换为 Microsoft Interop WdColorIndex