【问题标题】:ActionBar tab styles in horizontal view水平视图中的 ActionBar 选项卡样式
【发布时间】:2013-11-02 11:50:09
【问题描述】:

在纵向模式下使用手机或平板电脑时,选项卡会显示在包含徽标和菜单项的操作栏下方。在水平模式的平板电脑上,它们与徽标和菜单项一起显示。在此配置中,所选选项卡下的下划线会丢失。

什么风格控制这个?在纵向模式下,当标签与徽标和菜单内联显示时,我想使用与横向模式不同的选定样式。

我的主题的父级设置为Theme.AppCompat.Light。在它下面我有

<item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Silence</item>
<item name="android:actionBarStyle">@style/ActionBar.Solid.Silence</item>

android:actionBarTabStyleandroid:background 值设置为可绘制对象

<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_silence" />

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

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

    <!--    Focused states -->
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_silence" />
    <item android:state_focused="true" android:state_selected="true"  android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_silence" />
</selector>

我看到了这些state_selected 值。为这些设置为可绘制的图像与 ActionBar 背景颜色不同,所以不仅仅是我在相同颜色的背景上看不到它们。

actionBarStyle 的样式包含

<item name="android:background">@drawable/ab_solid_silence</item>
<item name="android:backgroundStacked">@drawable/ab_stacked_solid_silence</item>
<item name="android:backgroundSplit">@drawable/ab_bottom_solid_silence</item>
<item name="android:progressBarStyle">@style/ProgressBar.Silence</item>

前三个是图像,progressBarStyle 也包含一些样式,但它们无关紧要。

【问题讨论】:

  • 您是否针对各种 API 级别进行了检查(或者您在哪个版本上看到了这种行为?)?
  • @Luksprog 我只有运行 Android 4.1.2 和 4.3 的设备。如何为内联标签使用完全不同的图像?
  • actionBarTabStyle 负责该选择器。当标签内联时,我从未在消失的选项卡指示中看到过问题。 我如何为内联标签使用完全不同的图像? - 系统选择如何放置这些标签,横向可能会将它们作为内联。因此,您可以使用 -land 的配置标识符并将主题更改为所需的选择器。我建议不要这样做,我不确定我是否见过这样做的应用程序,这对用户来说是非常反直觉的。

标签: android android-actionbar android-tabs android-styles


【解决方案1】:

你应该对 ActionBarTabStyle 感兴趣。

要为内联标签使用不同的图像,您可以假设它代表横向模式并为横向模式创建自定义选择器。

如果您想尝试完整的选项集,请查看此 http://jgilfelt.github.io/android-actionbarstylegenerator 下载 zip,用您自己的 png 文件替换生成的图像并在您的项目中添加样式。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-18
    • 2012-10-28
    • 2017-10-17
    • 2017-05-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多