相关疑难解决方法(0)

使用选择器更改TextView文本颜色

我正在尝试使用TextView在tabhost上定义TabWidget的样式.

我刚刚为bgcolor创建了一个选择器并且工作正常,但我想为textColor创建一个选择器,但文本颜色不会改变:

这是我的tab_text_selector.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
     <item android:state_selected="true" android:color="@android:color/white" />
    <item android:state_focused="true" android:color="@android:color/white" />
    <item android:state_pressed="true" android:color="@android:color/white" />

</selector>
Run Code Online (Sandbox Code Playgroud)

当我尝试在textView上使用时,这是代码:

TextView txtTab=new TextView(this);
        txtTab.setTextColor(R.drawable.tab_text_selector);
        txtTab.setBackgroundResource(R.drawable.tab_bg_selector);
        txtTab.setGravity(Gravity.CENTER);
        txtTab.setText("Agregar Idea");
Run Code Online (Sandbox Code Playgroud)

我知道文本颜色在任何情况下都必须是白色,但事实并非如此.

android android-widget

44
推荐指数
5
解决办法
8万
查看次数

Android tabhost更改文本颜色样式

试图更改tabhost文本颜色,在此代码中我可以更改tabhost背景颜色(不是文本颜色)

tabHost.setOnTabChangedListener(new OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
          for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
            tabHost.getTabWidget().getChildAt(i)
                            .setBackgroundColor(Color.parseColor("#FF0000")); // unselected
          }

          tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab())
                        .setBackgroundColor(Color.parseColor("#0000FF")); // selected

        }
});
Run Code Online (Sandbox Code Playgroud)

如何更改tabhost文本颜色?

android android-tabhost

14
推荐指数
2
解决办法
4万
查看次数

标签 统计

android ×2

android-tabhost ×1

android-widget ×1