2013-10-30 62 views
1

我在Android中有一個Tabhost。我現在想知道如何將右側的按鈕放在自定義標題欄的頂部。下面是我的代碼:如何在Android中的標籤頂部添加自定義標題欄

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

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

傳遞一個繪製設置指標

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

你也可以傳遞將seletor id改爲getDrawable()。

這是一個很好的Tutorial

+0

答案是完全不相關的。 – user45678