Android操作栏标签和指标宽度问题

时间:2015-03-25 12:04:13

标签: android tabs android-actionbar android-appcompat

我有一个带有操作栏和操作栏标签的活动。我正在使用appcompat进行操作吧。我附上了屏幕截图。在模拟器4.4和htc 4.1.1选项卡宽度id正确但但在nexus 4,4.4上它增加了一些余量,因为它看起来很难看。

修改 我如何添加标签。

 ActionBar ab = getSupportActionBar();
  ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  ab.setTitle("Purchase media");
  ab.setSubtitle("To share with members");
  ab.addTab(ab.newTab().setText("Audios").setTabListener(this));
  ab.addTab(ab.newTab().setText("Videos").setTabListener(this));

我的标签样式如下

<style name="ActionBarTabStyle.Example" parent="@style/Widget.AppCompat.ActionBar.TabView">
    <item name="android:background">@drawable/tab_indicator_ab_example</item>
</style>

和标签指示符选择器如下

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@android:color/transparent" />
<item android:state_focused="false" android:state_selected="true"  android:state_pressed="false" android:drawable="@drawable/tab_selected_example" />

<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected_focused_example" />
<item android:state_focused="true" android:state_selected="true"  android:state_pressed="false" android:drawable="@drawable/tab_selected_focused_example" />

<!-- Pressed -->
<!--    Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_example" />
<item android:state_focused="false" android:state_selected="true"  android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_example" />

<!--    Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_example" />
<item android:state_focused="true" android:state_selected="true"  android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_example" />

它看起来如何。 wrong width of tabs and indicator 怎么样 correct width of tabs and indicator

有人对这种行为有任何想法吗?

0 个答案:

没有答案