我有以下用于选项卡式应用程序的活动代码。
public class TabbedActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabbedactivity);
TabHost tabHost = getTabHost();
TabSpec photospec = tabHost.newTabSpec("RP");
// setting Title and Icon for the Tab
photospec.setIndicator("RP", getResources().getDrawable(R.drawable.tabrp));
Intent photosIntent = new Intent(this, RP.class);
photospec.setContent(photosIntent);
// Tab for Songs
TabSpec songspec = tabHost.newTabSpec("MP");
songspec.setIndicator("MP", getResources().getDrawable(R.drawable.tabmp));
Intent songsIntent = new Intent(this, MP.class);
songspec.setContent(songsIntent);
tabHost.addTab(photospec);
tabHost.addTab(songspec);
}
}
tabbedactivity.xml 定义如下:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
</TabHost>
我添加了 tabmp.xml 和 tabrp.xml 如下:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="@color/white"/>
<item android:state_focused="true" android:drawable="@color/white"/>
<item android:state_pressed="true" android:drawable="@color/white"/>
<item android:drawable="@color/gray" />
</selector>
颜色定义在color.xml
. 应用程序运行,但选项卡上的颜色仍然是活动时默认的黑色,不活动时为灰色,按下时为蓝色,这是选项卡的默认 android 颜色。并且没有看到工作tabmp.xml
。tabrp.xml
我在这里做错了吗?