簡體   English   中英

如何在Android中的選項卡頂部使用按鈕添加自定義標題欄

[英]How to add Custom Titlebar with Button on top of Tabs in Android

我在Android中有一個Tabhost。 我現在想知道如何將“自定義標題欄”放在其頂部,並使用右側的按鈕。 下面是我的代碼:

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

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;
    }
}

傳遞可繪制設置指示器

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

您還可以將一個選擇器ID傳遞給getDrawable()。

這是一個很好的教程

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM