2015-04-01 50 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" 
      > 

我尝试了很多方法,但没有工作。所以我以这种方式实施。

相关问题