0

私はそうのようなのstyles.xmlにそれを追加使用してみました:Lollipopの前にボタンテキストを大文字にするにはどうすればよいですか?

<!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Main theme colors --> 
     <!-- your app branding color for the app bar --> 
     <item name="colorPrimary">@color/primary</item> 
     <!-- darker variant for the status bar and contextual app bars --> 
     <item name="colorPrimaryDark">@color/primary_dark</item> 
     <!-- theme UI controls like checkboxes and text fields --> 
     <item name="colorAccent">@color/accent</item> 

     <!-- buttons will not have shadows --> 
     <item name="android:buttonStyle">@style/Widget.AppCompat.Button.Borderless</item> 
     <item name="android:textAppearanceButton">@style/DefaultButtonTextStyle</item> 

     <item name="android:colorBackground">@android:color/white</item> 

    </style> 

<!--The button text style to be used throughout the app--> 
    <style name="DefaultButtonTextStyle" parent="@style/Base.TextAppearance.AppCompat.Button"> 
     <!-- Ensure that the buttons are all caps even pre Lollipop--> 
     <item name="android:textAllCaps">true</item> 
     <item name="textAllCaps">true</item> 
    </style> 

答えて

1

あなただけのようなあなたのボタンに設定してください次に、あなたのボタンの

<style name="CustomButton"> 
    <item name="android:layout_height">wrap_content</item> 
    <item name="android:layout_width">wrap_content</item> 
    <item name="android:layout_centerVertical">true</item> 
    <item name="android:textAllCaps">true</item> 
</style> 

をカスタムスタイルを作成する必要があります。

<Button 
    android:id="@+id/total_bill" 
    style="@style/CustomButton" /> 

または次のようにすることができます。

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
     <item name="buttonStyle">@style/MyButton</item> 
    </style> 

    <style name="MyButton" parent="Widget.AppCompat.Button"> 
     <item name="android:textAllCaps">true</item> 
    </style> 

2つ目の方法では、アプリケーション全体のすべてのボタンで変更されます。別の方法は、ボタンを拡張してカスタムボタンを作成し、textcapsをtrueに設定し、デフォルトのボタンの代わりにそのボタンを使用することです。

+0

私はと仮定しています。となるはずです Sree

+0

これはうまくいきました。私はそれ以前に、 @ style/MyButtonの代わりに @ style/MyButtonを行っていました。 「android:」という接頭辞はいつ追加しますか? – Sree

+0

アンドロイド特有の名前のためにアンドロイドを使用します:。カスタムテーマ名のためにアンドロイドを使う必要はありません:。 –

関連する問題