0

次のようにstyles.xmlに追加してみました:

<!-- 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>
4

1 に答える 1

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>

もう 1 つの方法は、Button を拡張し、textcaps が true に設定されているカスタム Button を作成し、デフォルトの Button の代わりにその Button を使用することです。

于 2016-06-20T16:18:22.677 に答える