Reputation: 75
I've created a button with background look as shown at picture below. Device on left emulator right.
The device is Samsung Galaxy SIII Emulator is Nexus 5
Button code :
This is the XML code of the button
<Button
android:id="@+id/button_main_start"
android:text="@string/button_Start"
android:textSize="30sp"
android:layout_width="270dp"
android:layout_height="60dp"
android:theme="@style/buttonTheme"
android:textAllCaps="false"
android:gravity="center_horizontal" />
<style name="buttonTheme" parent="android:style/Theme.NoTitleBar">
<item name="android:buttonStyle">@style/button</item>
</style>
<style name="button" parent="android:Widget.Button">
<item name="android:gravity">center_vertical|center_horizontal</item>
<item name="android:textColor">#FFFFFFFF</item>
<item name="android:shadowColor">#FF000000</item>
<item name="android:shadowDx">0</item>
<item name="android:shadowDy">-1</item>
<item name="android:shadowRadius">0.2</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">bold</item>
<item name="android:background">@drawable/button</item>
<item name="android:focusable">true</item>
<item name="android:clickable">true</item>
</style>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:startColor="#00CCFF"
android:centerColor="#0000CC"
android:endColor="#00CCFF"
android:angle="90"/>
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<stroke
android:width="2dip"
android:color="#FFFFFF" />
<corners android:radius= "8.0dp" />
</shape>
New to Mobile development so tell me if more information is needed.
MY SOULUTION: Not sure if this is the proper solution but I put "android:theme="@style/buttonTheme" in the manifest.xml and it worked out.
Upvotes: 2
Views: 1848
Reputation: 2804
You should check your layouts, you must have different layouts for different devices. Similarly check your styles, for different versions.
Update:
To test remove button theme and add android:background="@drawable/button"
Upvotes: 1
Reputation: 656
Pull <item name="android:background">@drawable/button</item>
from your style and add:
<style name="buttonTheme" parent="android:style/Theme.NoTitleBar">
<item name="android:buttonStyle">@style/button</item>
<item name="selectableItemBackground">@drawable/button</item>
</style>
to your theme.
Upvotes: 0