如何更改自定义选项卡的宽度?
how to change width of custom tab?
我正在尝试在操作栏中自定义选项卡。它在许多设备上工作正常,但有时它的宽度未设置为 match_parent。我使用 textview 作为自定义布局。我尝试了很多东西,比如我在 style.xml
中进行了更改
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:padding">0dp</item>
</style>
但是从上面的解决方案来看,我的其他布局变得如此卡住。因此,如果有人知道如何将自定义选项卡的大小扩大到 match_parent,这将真正帮助我,谢谢
你
==> 这是我尝试将 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));
终于找到解决办法了..
<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>
并且我将该操作栏 activity 主题设置为自定义主题。所以整个应用程序主题将是 Apptheme 但对于那个特定的 activity 我设置 custom_theme。
<activity android:name=".abc" android:theme="@style/custom_theme" android:launchMode="singleTask"
android:screenOrientation="portrait"
>
我尝试了很多方法,但 none 有效。所以我是这样实现的。
我正在尝试在操作栏中自定义选项卡。它在许多设备上工作正常,但有时它的宽度未设置为 match_parent。我使用 textview 作为自定义布局。我尝试了很多东西,比如我在 style.xml
中进行了更改<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:padding">0dp</item>
</style>
但是从上面的解决方案来看,我的其他布局变得如此卡住。因此,如果有人知道如何将自定义选项卡的大小扩大到 match_parent,这将真正帮助我,谢谢 你
==> 这是我尝试将 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));
终于找到解决办法了..
<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>
并且我将该操作栏 activity 主题设置为自定义主题。所以整个应用程序主题将是 Apptheme 但对于那个特定的 activity 我设置 custom_theme。
<activity android:name=".abc" android:theme="@style/custom_theme" android:launchMode="singleTask"
android:screenOrientation="portrait"
>
我尝试了很多方法,但 none 有效。所以我是这样实现的。