Android Button亿驾、TabLayout的英文字是大寫的?

參考

我的Android進(jìn)階之旅------>android Button上面的英文字符串自動大寫的問題解決
android在使用過程中账嚎,解決 Button 和 TabLayout 英文自動大寫的問題

如圖

1颊乘、未解決前的参淹,button內(nèi)英文文字是大寫的醉锄,而textview正常
0.png

2乏悄、解決后,button內(nèi)英文文字正常
1.png

解決

1恳不、第一個(gè)聯(lián)想到的就是button控件的大小寫屬性檩小,可是在button里我沒設(shè)置啊烟勋?奇怪规求。。卵惦。那就找找看哪里出了問題

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 沒有關(guān)于大小寫的沮尿。丛塌。繼續(xù)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 也沒有大小寫的畜疾。赴邻。。只能前往系統(tǒng)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啡捶、這個(gè)是一層層追溯到系統(tǒng)的button style最后的姥敛。黃天不負(fù)有心人,終于找到:\color{red}{textAllCaps=true是控制文字大寫瞎暑,在android 5.0后彤敛,button屬性的默認(rèn)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一般不單獨(dú)使用theme,那么就會默認(rèn)使用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>

其他

最后說一句嫂拴,其實(shí)你button沒有style播揪,但是application有theme的話,那么按照theme一層層找下去筒狠,也能找到button用的style或者textview用的style,比方說:

好長猪狈,還能繼續(xù)往下,反正就是這個(gè)意思辩恼。雇庙。谓形。

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

最后

總結(jié):小問題,也需要折騰下疆前!
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末寒跳,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子竹椒,更是在濱河造成了極大的恐慌童太,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,509評論 6 504
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件胸完,死亡現(xiàn)場離奇詭異书释,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)赊窥,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,806評論 3 394
  • 文/潘曉璐 我一進(jìn)店門爆惧,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人锨能,你說我怎么就攤上這事扯再。” “怎么了腹侣?”我有些...
    開封第一講書人閱讀 163,875評論 0 354
  • 文/不壞的土叔 我叫張陵叔收,是天一觀的道長。 經(jīng)常有香客問我傲隶,道長饺律,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,441評論 1 293
  • 正文 為了忘掉前任跺株,我火速辦了婚禮复濒,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘乒省。我一直安慰自己巧颈,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,488評論 6 392
  • 文/花漫 我一把揭開白布袖扛。 她就那樣靜靜地躺著砸泛,像睡著了一般。 火紅的嫁衣襯著肌膚如雪蛆封。 梳的紋絲不亂的頭發(fā)上唇礁,一...
    開封第一講書人閱讀 51,365評論 1 302
  • 那天,我揣著相機(jī)與錄音惨篱,去河邊找鬼盏筐。 笑死,一個(gè)胖子當(dāng)著我的面吹牛砸讳,可吹牛的內(nèi)容都是我干的琢融。 我是一名探鬼主播界牡,決...
    沈念sama閱讀 40,190評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼漾抬!你這毒婦竟也來了宿亡?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,062評論 0 276
  • 序言:老撾萬榮一對情侶失蹤奋蔚,失蹤者是張志新(化名)和其女友劉穎她混,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體泊碑,經(jīng)...
    沈念sama閱讀 45,500評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,706評論 3 335
  • 正文 我和宋清朗相戀三年毯欣,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了馒过。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,834評論 1 347
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡酗钞,死狀恐怖腹忽,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情砚作,我是刑警寧澤窘奏,帶...
    沈念sama閱讀 35,559評論 5 345
  • 正文 年R本政府宣布,位于F島的核電站葫录,受9級特大地震影響着裹,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜米同,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,167評論 3 328
  • 文/蒙蒙 一骇扇、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧面粮,春花似錦少孝、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,779評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至柴底,卻和暖如春婿脸,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背似枕。 一陣腳步聲響...
    開封第一講書人閱讀 32,912評論 1 269
  • 我被黑心中介騙來泰國打工盖淡, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人凿歼。 一個(gè)月前我還...
    沈念sama閱讀 47,958評論 2 370
  • 正文 我出身青樓褪迟,卻偏偏與公主長得像冗恨,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個(gè)殘疾皇子味赃,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,779評論 2 354

推薦閱讀更多精彩內(nèi)容