ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

android – 如何使用AppCompat库更改选项卡样式和颜色

2019-08-25 07:37:24  阅读:137  来源: 互联网

标签:android android-styles android-actionbar-compat


我正在制作一个小程序,我正在使用带有滑动的Fragment Tabs,使其时尚,我使用Style Generator,我的经验很好.

现在我想对我的标签的现有外观进行一些小改动,这次我谈的是Tab Text样式.

第一次查看我简单时尚的ActionBar屏幕截图

就像我们可以看到所有Tab的文本看起来都相同,所以在这里我需要你的帮助,在我的情况下,所选Tab的文本样式将保持相同的白色为粗体,因为它看起来,但想要正常更改其他人的文本样式(我的意思是那些不是选择像: – IOS和WINDOWS)

styles.xml:

<resources>

    <style name="Theme.Compatstyle4" parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <item name="actionBarItemBackground">@drawable/selectable_background_compatstyle4</item>
        <item name="popupMenuStyle">@style/PopupMenu.Compatstyle4</item>
        <item name="dropDownListViewStyle">@style/DropDownListView.Compatstyle4</item>
        <item name="actionBarTabStyle">@style/ActionBarTabStyle.Compatstyle4</item>
        <item name="actionDropDownStyle">@style/DropDownNav.Compatstyle4</item>
        <item name="actionBarStyle">@style/ActionBar.Solid.Compatstyle4</item>
        <item name="actionModeBackground">@drawable/cab_background_top_compatstyle4</item>
        <item name="actionModeSplitBackground">@drawable/cab_background_bottom_compatstyle4</item>
        <item name="actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Compatstyle4</item>

                <!-- Light.DarkActionBar specific -->
        <item name="actionBarWidgetTheme">@style/Theme.Compatstyle4.Widget</item>

    </style>

    <style name="ActionBar.Solid.Compatstyle4" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
        <item name="background">@drawable/ab_solid_compatstyle4</item>
        <item name="backgroundStacked">@drawable/ab_stacked_solid_compatstyle4</item>
        <item name="backgroundSplit">@drawable/ab_bottom_solid_compatstyle4</item>
        <item name="progressBarStyle">@style/ProgressBar.Compatstyle4</item>
    </style>

    <style name="ActionBar.Transparent.Compatstyle4" parent="@style/Widget.AppCompat.ActionBar">
        <item name="background">@drawable/ab_transparent_compatstyle4</item>
        <item name="progressBarStyle">@style/ProgressBar.Compatstyle4</item>
    </style>

    <style name="PopupMenu.Compatstyle4" parent="@style/Widget.AppCompat.PopupMenu">    
        <item name="android:popupBackground">@drawable/menu_dropdown_panel_compatstyle4</item>  
    </style>

    <style name="DropDownListView.Compatstyle4" parent="@style/Widget.AppCompat.ListView.DropDown">
        <item name="android:listSelector">@drawable/selectable_background_compatstyle4</item>
    </style>

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

    <style name="DropDownNav.Compatstyle4" parent="@style/Widget.AppCompat.Spinner.DropDown.ActionBar">
        <item name="android:background">@drawable/spinner_background_ab_compatstyle4</item>
        <item name="android:popupBackground">@drawable/menu_dropdown_panel_compatstyle4</item>
        <item name="android:dropDownSelector">@drawable/selectable_background_compatstyle4</item>
    </style>

    <style name="ProgressBar.Compatstyle4" parent="@style/Widget.AppCompat.ProgressBar.Horizontal">
        <item name="android:progressDrawable">@drawable/progress_horizontal_compatstyle4</item>
    </style>

    <style name="ActionButton.CloseMode.Compatstyle4" parent="@style/Widget.AppCompat.ActionButton.CloseMode">
        <item name="android:background">@drawable/btn_cab_done_compatstyle4</item>
    </style>

    <!-- this style is only referenced in a Light.DarkActionBar based theme -->
    <style name="Theme.Compatstyle4.Widget" parent="@style/Theme.AppCompat">
        <item name="popupMenuStyle">@style/PopupMenu.Compatstyle4</item>
        <item name="dropDownListViewStyle">@style/DropDownListView.Compatstyle4</item>
    </style>

</resources>

喜欢:我想将文本颜色显示为所选选项卡的默认颜色,将灰色显示为其他选项卡

解决方法:

您需要在三个地方进行设置.

>您的ActionBAr主题,我将tabstyle设置为下面定义的自定义方式.

<!-- All customizations that are NOT specific to a particular API-level can go here. -->

<item name="actionBarTabStyle">@style/CustomActionBarTabs</item>
<item name="actionBarTabTextStyle">@style/CustomActionBarTabs_TextColor</item>              

>我的自定义标签样式,指的是各种状态的可绘制选择器.

<!-- action bar tab styles -->
<style name="CustomActionBarTabs" parent="@style/Widget.AppCompat.ActionBar.TabView">
   <item name="android:background">@drawable/tab_indicator_ab_custom_actionbar_style</item>
   <item name="android:textColor">#666666</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_custom_actionbar_style" />

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

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

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

标签:android,android-styles,android-actionbar-compat
来源: https://codeday.me/bug/20190825/1716779.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有