【问题标题】:how style tabactivity in android如何在android中设置tabactivity
【发布时间】:2013-06-15 03:44:18
【问题描述】:

您好,我正在尝试使用此设置我的 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,后来我的标签显示完全黑色,我想对其进行样式设置以使其更漂亮。

非常感谢。

【问题讨论】:

    标签: android android-tabhost android-tabs android-tabactivity


    【解决方案1】:

    为什么不能使用 Fragments。要支持所有版本,请使用 Action bar Sherlock 库

    http://wptrafficanalyzer.in/blog/adding-navigation-tabs-containing-listview-to-action-bar-in-pre-honeycomb-versions-using-sherlock-library/

    【讨论】:

    • 它是我的最佳选择吗?但是我不喜欢夏洛克风格的黑蓝色,我可以改变它看起来很好吗?
    • 如果我使用sherlock,我需要使用片段吗?您认为我需要更改很多实际代码吗?让它工作?
    【解决方案2】:

    仅供参考 TabActivity 已弃用。

    相反,你为什么不使用带有选项卡的 ActionBar 并提供兼容性,你可以使用ActionBarSherlock

    什么是 ActionBarSherlock?

    ActionBarSherlock 是支持库的扩展,旨在 促进在所有应用中使用操作栏设计模式 具有单个 API 的 Android 版本。

    【讨论】:

    • 是的,我知道,所以这是我最好的选择?我可以在不更改太多代码的情况下将我的应用程序转为使用该夏洛克吗?
    • 我怎样才能开始将该选项卡活动重写为操作栏?但是 tabhost 也被弃用了?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-04
    • 1970-01-01
    相关资源
    最近更新 更多