如何更改自定义标签的宽度?

时间:2015-04-01 09:13:54

标签: android android-layout android-actionbar

我正在尝试在操作栏中自定义标签。它在许多设备中工作正常,但有时其宽度未设置为match_parent。我使用textview作为自定义布局。我尝试了很多像我在style.xml中更改的东西

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

但从上层解决方案来看,我的其他布局变得非常紧张。所以,如果有人知道如何将自定义标签的大小放大到match_parent,那将真的帮助我谢谢 你

this is how it looks.

==&GT;这是我的代码,我尝试将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)); 

1 个答案:

答案 0 :(得分:1)

Atlast我得到了解决方案..

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

这是我的App主题,所以我将其更改为:

<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"
            >
我试过很多方法,但没有办法。所以我实现这种方式。

相关问题