GibboK
GibboK

Reputation: 73928

How to apply a buttonStyle in Android?

I have this Theme,

<style name="AppTheme" parent="@style/AppBaseTheme">
    <item name="android:buttonStyle">@style/MyButtonStyle</item>
</style>

I need to define another style for a button (called MyButtonStyleDealer).

Using the following code I get error android:buttonStyle has been already defined.

<style name="AppTheme" parent="@style/AppBaseTheme">
    <item name="android:buttonStyle">@style/MyButtonStyle</item>
    <item name="android:buttonStyle">@style/MyButtonStyleDealer</item>
</style>

I would like to know if it possible define a second style for the button and how to apply it to the View.

Upvotes: 2

Views: 225

Answers (3)

Solenya
Solenya

Reputation: 694

You can set sepecific styles like this:

<Button    
android:id="@+id/button_send"    
android:layout_width="wrap_content"    
android:layout_height="wrap_content"    
android:text="@string/button_send"    
android:onClick="sendMessage"    
style="?android:attr/MyButtonStyleDealer" />

Upvotes: 0

Blackbelt
Blackbelt

Reputation: 157457

If got your question correctly, you can add inside your style file another entry for the button

 <style name="MyNotClickableButtonStyle">
    <item name="android:background">@drawable/my_button_background</item>
    <item name="android:clickable">false</item>
</style>

and inside your layout,

<Button 
     style="@style/MyNotClickableButtonStyle"

Upvotes: 3

Alfaplus
Alfaplus

Reputation: 1723

You only can define one android:buttonStyle. If you want to change only this the button style has to add another style.

Another properties can be used if you want but only once. For instance:

<style name="GlobalAppTheme" parent="Theme.Sherlock.Light">
        <item name="android:actionBarStyle">@style/ActionBar</item>
        <item name="actionBarStyle">@style/ActionBar</item>
        <item name="android:editTextStyle">@style/GlobalTextView</item>
        <item name="android:textColor">@color/text_gray</item>
        <item name="android:checkboxStyle">@style/CheckBox</item>
        <item name="android:radioButtonStyle">@style/RadioButton</item>
        <item name="android:buttonStyle">@style/Button</item>
        <item name="android:textSize">14sp</item>
        <item name="android:actionBarItemBackground">@android:color/transparent</item>
        <item name="actionBarItemBackground">@android:color/transparent</item>
        <item name="android:alertDialogStyle">@style/Theme.Sherlock.Light.Dialog</item>
    </style>

<style name="GlobalAppTheme2" parent="Theme.Sherlock.Light">
            <item name="android:actionBarStyle">@style/ActionBar</item>
            <item name="actionBarStyle">@style/ActionBar</item>
            <item name="android:editTextStyle">@style/GlobalTextView</item>
            <item name="android:textColor">@color/text_gray</item>
            <item name="android:checkboxStyle">@style/CheckBox</item>
            <item name="android:radioButtonStyle">@style/RadioButton</item>
            <item name="android:buttonStyle">@style/Button</item>
            <item name="android:textSize">14sp</item>
            <item name="android:actionBarItemBackground">@android:color/transparent</item>
            <item name="actionBarItemBackground">@android:color/transparent</item>
            <item name="android:alertDialogStyle">@style/Theme.Sherlock.Light.Dialog</item>
        </style>

Upvotes: 0

Related Questions