嗨,我正在尝试使用以下方式设置我的 tabactivity 的样式:
public class TabContainer extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tab_container);
//TabHost tabHost = (TabHost) findViewById(R.id.tabhost);
TabHost tabHost = getTabHost();
// Tab for Radio
TabSpec radioTabSpec = tabHost.newTabSpec("Radio Online");
// setting Title and Icon for the Tab
radioTabSpec.setIndicator("Radio Online", getResources().getDrawable(R.drawable.menu_radio));
Intent radioIntent = new Intent(this, MainActivity.class);
radioTabSpec.setContent(radioIntent);
// Tab for Facebook
TabSpec facebookTabSpec = tabHost.newTabSpec("Facebook");
facebookTabSpec.setIndicator("Facebook", getResources().getDrawable(R.drawable.menu_facebook));
Intent facebookIntent = new Intent(this, FacebookActivity.class);
facebookTabSpec.setContent(facebookIntent);
// Tab for Twitter
TabSpec twitterTabSpec = tabHost.newTabSpec("Twitter");
twitterTabSpec.setIndicator("Twitter", getResources().getDrawable(R.drawable.menu_twitter));
Intent twitterIntent = new Intent(this, TwitterActivity.class);
twitterTabSpec.setContent(twitterIntent);
// Tab for About
TabSpec aboutTabSpec = tabHost.newTabSpec("Acerca");
aboutTabSpec.setIndicator("Acerca", getResources().getDrawable(R.drawable.menu_about));
Intent aboutIntent = new Intent(this, AboutActivity.class);
aboutTabSpec.setContent(aboutIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(radioTabSpec); // Adding photos tab
tabHost.addTab(facebookTabSpec); // Adding songs tab
tabHost.addTab(twitterTabSpec); // Adding videos tab
tabHost.addTab(aboutTabSpec); // Adding videos tab
}
}
这是我的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="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</TabHost>
选项卡样式示例:
我知道 tabactivity 很旧,但我找不到任何其他方法让它适用于 android 2.3,后来我的标签显示完全黑色,我想对其进行样式设置以使其更漂亮。
非常感谢您。