Java 安卓如何更改选项卡文本颜色?

Java 安卓如何更改选项卡文本颜色?,java,android,colors,styles,textcolor,Java,Android,Colors,Styles,Textcolor,我想设置标签文本的颜色为白色,我找不到任何好的教程。有人能帮我吗 这是我的选项卡活动: package com.example.dev.nordugrid; import android.app.TabActivity; import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceMa

我想设置标签文本的颜色为白色,我找不到任何好的教程。有人能帮我吗

这是我的选项卡活动:

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;
        }

    });
}
}
package com.example.dev.nordugrid;
导入android.app.TabActivity;
导入android.content.Context;
导入android.content.SharedReferences;
导入android.os.Bundle;
导入android.preference.PreferenceManager;
导入android.util.Log;
导入android.view.view;
导入android.view.Window;
导入android.widget.AdapterView;
导入android.widget.ArrayAdapter;
导入android.widget.Button;
导入android.widget.ListView;
导入android.widget.TabHost;
导入android.widget.TextView;
导入android.widget.Toast;
导入android.widget.TabHost.TabSpec;
导入java.util.ArrayList;
导入java.util.List;
导入java.util.Random;
@抑制警告(“弃用”)
公共类Busena扩展了活动{
共享引用优先权;
TextView proxySuteike,proxyGaliojimas;
按钮4;
公共整数随机整数;
串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串串;
按钮座;
private ArrayList m_parts=new ArrayList();
私有可运行视图部件;
专用项目适配器m_适配器;
私有最终字符串数据[]={“Android”、“iPhone”、“BlackBerry”、“AndroidPeople”};
私有最终字符串data2[]={“Ivykdyta”、“Atsaukta”、“Einama”、“Nusisnekejo”};
列表a=新的ArrayList();
列表b=新的ArrayList();
公共静态void setDefaults(字符串键、字符串值、上下文){
SharedReferences prefs=PreferenceManager.GetDefaultSharedReferences(上下文);
SharedReferences.Editor=prefs.edit();
编辑器.putString(键,值);
commit();
}
公共静态字符串getDefaults(字符串键、上下文){
SharedReferences首选项=PreferenceManager.GetDefaultSharedReferences(上下文);
返回preferences.getString(key,null);
}
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE\u NO\u TITLE);
这个.setContentView(R.layout.activity_busena);
this.setTheme(R.style.listItem);
holder=(按钮)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(“kitifailaikiksme”,this);
ListView列表=(ListView)findViewById(R.id.tab1);
m_零件添加(新项目(stringUzduotiesPav、stringUzduotiesJDL));
m_adapter=新项目适配器(此,R.layout.row,m_部件);
列表.设置适配器(m_适配器);
button4=(按钮)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();
}
/*@凌驾
受保护的void onListItemClick(列表视图l、视图v、整数位置、长id){
字符串项=(字符串)getListAdapter().getItem(位置);
Toast.makeText(此项+选定项),Toast.LENGTH_LONG.show();
}*/
私有void setNewTab(上下文上下文、TabHost TabHost、字符串标记、int-title、int-icon、int-contentID){
TabSpec TabSpec=tabHost.newTabSpec(标签);
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(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
int-skaicius=randomInt;
Random randomGenerator=新的Random();
int rand=randomGenerator.nextInt(240斯卡休斯);
字符串ats=Integer.toString(randomInt);
proxyGaliojimas.setText(ats+“最小值”);
randomInt=rand;
}
});
}
}
这就是我所看到的:

这是选项卡活动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;
}

在布局文件夹中创建自定义_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"/>
答案可能重复在这里
是红色的…:)它说“必须声明元素textview”
tabHost.newTabSpec("Tab1").setIndicator(createTabView(getApplicationContext(),"Tab_name"))