And*_*eir 5 android android-widget android-layout
我在冰淇淋三明治应用程序中使用TabHost/TabWidget的折旧库.我没有时间熟悉ActionBarSherlock,所以我必须以我知道的方式进入应用程序.
我想知道我怎么能去造型的TabWidget及其Tab对象,更改所选标签的颜色,对背景颜色和图像?使用标准样式和主题似乎不起作用.
假设已弃用的库按原样运行,就像它应该的那样,这是我用来为我的选项卡着色的过程.我只是在代码中设置背景如下,因为它在xml中无法直接访问:
TabWidget tabs = (TabWidget)getTabWidget();
for (int i = 0; i<tabs.getChildCount(); i++) {
RelativeLayout tab = (RelativeLayout) tabs.getChildAt(i);
tab.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.tabindicator));
Run Code Online (Sandbox Code Playgroud)
tabindicator drawable如下:
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected" />
<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_focus" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_focus" />
<!-- Pressed -->
<item android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_press" />
<item android:state_pressed="true" android:drawable="@drawable/tab_press" />
</selector>
Run Code Online (Sandbox Code Playgroud)
尽管您可以使用标准颜色获得类似的效果,但是可绘制的颜色只有9个补丁图像.
归档时间: |
|
查看次数: |
1595 次 |
最近记录: |