2015-04-01 49 views
0

我想在操作欄中定製選項卡。它在許多設備上工作正常,但有時其寬度未設置爲match_parent。我已經使用textview作爲自定義佈局。我試過很多東西就像我在style.xml如何更改自定義選項卡的寬度?

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="android:padding">0dp</item> </style>

但是從上解決我的其他佈局變得如此stucked了改變。所以如果有人知道如何擴大自定義選項卡的大小match_parent比它真的會幫我謝謝你

this is how it looks.

==>這是從那裏我嘗試設置的TextView我的代碼爲製表符

TextView textView=new TextView(getApplicationContext()); 
      textView.setText(tab_name); 
      textView.setGravity(Gravity.CENTER); 
      textView.setTextSize(20.0f); 


      textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); 
      textView.setPadding(20,0,20,0); 
      textView.setBackgroundColor(Color.parseColor("#ffffff")); 
      textView.setTextColor(Color.parseColor("#000000")); 
      textView.setTypeface(customFont); 

      actionBar.addTab(actionBar.newTab().setText(tab_name).setCustomView(textView) 
       .setTabListener(this)); 
+0

給予從左到右的平等填充這些textviews的佈局 – 2015-04-01 09:20:43

+0

@AnshulTyagi它沒有工作。 :( – 2015-04-01 09:29:15

+0

張貼您的xml代碼並提及它們。我會爲您編輯 – 2015-04-01 09:29:49

回答

0

Atlast我得到了解決這個..

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
    </style> 

,這是第一次在我的應用程序的主題,所以我把它改成:

<style name="AppTheme" parent="Theme.AppCompat.Light"> 
      <!-- Customize your theme here. --> 
     </style> 

,幷包括了其他風格的ActionBar

<style name="custom_theme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <item name="android:padding">0dp</item> 


    </style> 

,我設置操作欄的活動主題自定義主題。所以整個應用程序的主題將是Apptheme,但對於我設置custom_theme的那個特定活動。

<activity android:name=".abc" android:theme="@style/custom_theme" android:launchMode="singleTask" 
      android:screenOrientation="portrait" 
      > 

我嘗試了很多方法,但沒有工作。所以我以這種方式實施。

相關問題