Android系统。如何更改标签文字颜色?

时间:2015-05-01 14:25:14

标签: 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.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

这是标签活动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>

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

1 个答案:

答案 0 :(得分:0)

创建此方法: -

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"))