Android Button、TabLayout的英文字是大写的?

简介: 参考我的Android进阶之旅------>android Button上面的英文字符串自动大写的问题解决android在使用过程中,解决 Button 和 TabLayout 英文自动大写的问题如图1、未解决前的,button内英文文字是大写的,而textview正常0.png2、解决后,button内英文文字正常1.png解决1、第一个联想到的就是button控件的大小写属性,可是在button里我没设置啊?奇怪。

参考

我的Android进阶之旅------>android Button上面的英文字符串自动大写的问题解决
android在使用过程中,解决 Button 和 TabLayout 英文自动大写的问题

如图

1、未解决前的,button内英文文字是大写的,而textview正常
img_72b8537467854aff2755a94800de37e2.png
0.png

2、解决后,button内英文文字正常
img_8f179a098ed43ffa304ca97cd5e71b64.png
1.png

解决

1、第一个联想到的就是button控件的大小写属性,可是在button里我没设置啊?奇怪。。。那就找找看哪里出了问题

1.1、layout中的button,用的style=btn_normal_style

<Button
            android:id="@+id/btn_show_dialog"
            style="@style/btn_normal_style"
            android:text="弹出Dialog" />

1.2、btn_normal_style 没有关于大小写的。。继续btn_base_style

    <!-- button style -->
    <style name="btn_normal_style" parent="@style/btn_base_style">
        <item name="android:textColor">@color/wx_text_white</item>
        <item name="android:textSize">@dimen/normal_text_size</item>
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
    </style>

1.3、btn_base_style 也没有大小写的。。。只能前往系统api的style看了

<style name="btn_base_style" parent="Base.TextAppearance.AppCompat.Widget.Button">
        <item name="android:textColor">@color/wx_text_white</item>
        <item name="android:textSize">@dimen/normal_text_size</item>
    </style>

1.4、这个是一层层追溯到系统的button style最后的。黄天不负有心人,终于找到:\color{red}{textAllCaps=true是控制文字大写,在android 5.0后,button属性的默认textAllCaps被改成true了}

<style name="Base.TextAppearance.AppCompat.Button">
        <item name="android:textSize">@dimen/abc_text_size_button_material</item>
        <item name="android:textAllCaps">true</item>
        <item name="android:textColor">?android:textColorPrimary</item>
    </style>
2、问题解决方案

2.1、直接在button的style中添加textAllCaps=false

<style name="btn_base_style" parent="Base.TextAppearance.AppCompat.Widget.Button">
        ...
        <!-- 5.0 sdk material button default textAllCaps=true -->
        <item name="textAllCaps">false</item>
</style>

2.2、上面只针对继承了btn_base_style的button有效,如果想一劳永逸,那么直接修改theme的值

工程使用theme是自定义的AppTheme,且其他activity一般不单独使用theme,那么就会默认使用application的theme

<application
        ...
        android:theme="@style/AppTheme">
        ...
</application>

然后在AppTheme中添加textAllCaps=false

<!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        ...
        <!-- 5.0 sdk material button default textAllCaps=true -->
        <item name="textAllCaps">false</item>
    </style>

其他

最后说一句,其实你button没有style,但是application有theme的话,那么按照theme一层层找下去,也能找到button用的style或者textview用的style,比方说:

好长,还能继续往下,反正就是这个意思。。。

<style name="Platform.AppCompat.Light" parent="android:Theme.Holo.Light">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowActionBar">false</item>

        <item name="android:buttonBarStyle">?attr/buttonBarStyle</item>
        <item name="android:buttonBarButtonStyle">?attr/buttonBarButtonStyle</item>
        <item name="android:borderlessButtonStyle">?attr/borderlessButtonStyle</item>

        <!-- Window colors -->
        <item name="android:colorForeground">@color/foreground_material_light</item>
        <item name="android:colorForegroundInverse">@color/foreground_material_dark</item>
        <item name="android:colorBackground">@color/background_material_light</item>
        <item name="android:colorBackgroundCacheHint">@color/abc_background_cache_hint_selector_material_light</item>
        <item name="android:disabledAlpha">@dimen/abc_disabled_alpha_material_light</item>
        <item name="android:backgroundDimAmount">0.6</item>
        <item name="android:windowBackground">@color/background_material_light</item>

        <!-- Text colors -->
        <item name="android:textColorPrimary">@color/abc_primary_text_material_light</item>
        <item name="android:textColorPrimaryInverse">@color/abc_primary_text_material_dark</item>
        <item name="android:textColorSecondary">@color/abc_secondary_text_material_light</item>
        <item name="android:textColorSecondaryInverse">@color/abc_secondary_text_material_dark</item>
        <item name="android:textColorTertiary">@color/abc_secondary_text_material_light</item>
        <item name="android:textColorTertiaryInverse">@color/abc_secondary_text_material_dark</item>
        <item name="android:textColorPrimaryDisableOnly">@color/abc_primary_text_disable_only_material_light</item>
        <item name="android:textColorPrimaryInverseDisableOnly">@color/abc_primary_text_disable_only_material_dark</item>
        <item name="android:textColorHint">@color/abc_hint_foreground_material_light</item>
        <item name="android:textColorHintInverse">@color/abc_hint_foreground_material_dark</item>
        <item name="android:textColorHighlight">@color/highlighted_text_material_light</item>
        <item name="android:textColorHighlightInverse">@color/highlighted_text_material_dark</item>
        <item name="android:textColorLink">?attr/colorAccent</item>
        <item name="android:textColorLinkInverse">?attr/colorAccent</item>
        <item name="android:textColorAlertDialogListItem">@color/abc_primary_text_material_light</item>

        <!-- Text styles -->
        <item name="android:textAppearance">@style/TextAppearance.AppCompat</item>
        <item name="android:textAppearanceInverse">@style/TextAppearance.AppCompat.Inverse</item>
        <item name="android:textAppearanceLarge">@style/TextAppearance.AppCompat.Large</item>
        <item name="android:textAppearanceLargeInverse">@style/TextAppearance.AppCompat.Large.Inverse</item>
        <item name="android:textAppearanceMedium">@style/TextAppearance.AppCompat.Medium</item>
        <item name="android:textAppearanceMediumInverse">@style/TextAppearance.AppCompat.Medium.Inverse</item>
        <item name="android:textAppearanceSmall">@style/TextAppearance.AppCompat.Small</item>
        <item name="android:textAppearanceSmallInverse">@style/TextAppearance.AppCompat.Small.Inverse</item>

        <item name="android:listChoiceIndicatorSingle">@drawable/abc_btn_radio_material</item>
        <item name="android:listChoiceIndicatorMultiple">@drawable/abc_btn_check_material</item>

        <item name="android:listPreferredItemPaddingLeft">@dimen/abc_list_item_padding_horizontal_material</item>
        <item name="android:listPreferredItemPaddingRight">@dimen/abc_list_item_padding_horizontal_material</item>

        <item name="android:actionModeCutDrawable">?actionModeCutDrawable</item>
        <item name="android:actionModeCopyDrawable">?actionModeCopyDrawable</item>
        <item name="android:actionModePasteDrawable">?actionModePasteDrawable</item>
        <item name="android:actionModeSelectAllDrawable">?actionModeSelectAllDrawable</item>

        <item name="android:textSelectHandle">@drawable/abc_text_select_handle_middle_mtrl_light</item>
        <item name="android:textSelectHandleLeft">@drawable/abc_text_select_handle_left_mtrl_light</item>
        <item name="android:textSelectHandleRight">@drawable/abc_text_select_handle_right_mtrl_light</item>
    </style>

TabLayout解决方案

app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget"

最后

总结:小问题,也需要折腾下!
目录
相关文章
|
4月前
|
Android开发
android 快速更改TabLayout的选中背景颜色。
android 快速更改TabLayout的选中背景颜色。
77 0
|
3月前
|
XML Java Android开发
15. 【Android教程】按钮 Button/ImageButton
15. 【Android教程】按钮 Button/ImageButton
38 2
|
4月前
|
XML Android开发 数据格式
Android下自定义Button样式
Android下自定义Button样式
37 3
|
4月前
|
Android开发
Android 开发 tablayout 字体加粗 ,简便的手法:
Android 开发 tablayout 字体加粗 ,简便的手法:
60 0
|
XML Android开发 数据格式
Android中利用shape属性自定义设置Button按钮
Android中利用shape属性自定义设置Button按钮
195 0
|
4月前
|
XML Java Android开发
Android Studio App开发中工具栏Toolbar、溢出菜单OverflowMenu、标签布局TabLayout的讲解及实战(实现京东App的标签导航栏,附源码)
Android Studio App开发中工具栏Toolbar、溢出菜单OverflowMenu、标签布局TabLayout的讲解及实战(实现京东App的标签导航栏,附源码)
510 0
|
XML Android开发 数据格式
Android Button 属性介绍与使用
Android Button 属性介绍与使用
283 0
|
Android开发
#5,Android Studio Android 按钮 button
#5,Android Studio Android 按钮 button
|
缓存 Android开发
Android TabLayout的使用详解
Android TabLayout的使用详解
120 0
|
Android开发
Android Button 设置 android:background=“@drawable/xxx“ 无效
Android Button 设置 android:background=“@drawable/xxx“ 无效
151 0