参考
我的Android进阶之旅------>android Button上面的英文字符串自动大写的问题解决
android在使用过程中,解决 Button 和 TabLayout 英文自动大写的问题
如图
1、未解决前的,button内英文文字是大写的,而textview正常解决
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最后的。黄天不负有心人,终于找到:
<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"