简体   繁体   English

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

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

I have a Tabhost in Android. 我在Android中有一个Tabhost。 I now want to know how can i put Custom Titlebar on top of it with button on right. 我现在想知道如何将“自定义标题栏”放在其顶部,并使用右侧的按钮。 Below is my code : 下面是我的代码:

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

support.xml 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 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;
    }
}

Pass a drawable to set indicator 传递可绘制设置指示器

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

you may also pass a seletor id to getDrawable(). 您还可以将一个选择器ID传递给getDrawable()。

here is a good Tutorial 这是一个很好的教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM