如何在Android中的选项卡顶部添加带有按钮的自定义标题栏

时间:2013-10-30 12:37:13

标签: android button tabs titlebar

我在Android中有一个Tabhost。我现在想知道如何使用右侧的按钮将Custom Titlebar放在它上面。以下是我的代码:

++++++++++++++++++++++++++
+                +++++++ +
+                +++++++ +
++++++++++++++++++++++++++
+           +            +
+           +            +
++++++++++++++++++++++++++      

support.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:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:padding="5dp" >

            <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"
                android:padding="5dp" />
        </LinearLayout>

    </TabHost>

Support.java

public class Support extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        setContentView(R.layout.support);
        Bundle bundle = getIntent().getExtras();

        TabHost tabHost = getTabHost();
        TabHost.TabSpec spec;
        Intent intent;

        intent = new Intent().setClass(this, TestListView.class);
        spec = tabHost  .newTabSpec("some_things")
                        .setIndicator("Info")
                        .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, TestListView.class);
        spec = tabHost  .newTabSpec("top_things")
                        .setIndicator("Log")
                        .setContent(intent);
        tabHost.addTab(spec);


        tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 85;
        tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 85;
    }
}

1 个答案:

答案 0 :(得分:1)

传递drawable以设置指标

.setIndicator("Log",getResources().getDrawable(R.drawable.image_log));

您也可以将seletor id传递给getDrawable()。

这是一个很好的Tutorial