Reputation: 8626
I have made style with following code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CodeFont" parent="@android:style/TextAppearance.Medium">
<item name="android:layout_width">150dip</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#00FF00</item>
<item name="android:typeface">monospace</item>
</style>
</resources>
And applied it as:
<EditText
style="CodeFont"
android:id="@+id/txt_username"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
but its not getting applied.
If i write same style in as:
<EditText
android:id="@+id/txt_username"
android:layout_width="150dip"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:ems="10"
android:inputType="textPersonName" />
Then it gets applied.
Is there anything wrong with my code?
Upvotes: 4
Views: 3919
Reputation: 133560
The proper way to set the style is:
style="@style/CodeFont"
For more info check the docs
http://developer.android.com/guide/topics/ui/themes.html
Also check styles.xml
Upvotes: 7
Reputation: 24848
**themes.xml**
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="ijoomer_theme" parent="define your parent theme here">
<item name="edittext">@style/CodeFont</item>
</style>
</resources>
**attrs.xml**
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="edittext" format="reference" />
</resources>
**style.xml**
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CodeFont" parent="@android:style/TextAppearance.Medium">
<item name="android:layout_width">150dip</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#00FF00</item>
<item name="android:typeface">monospace</item>
</style>
</resources>
**use edittext style**
<EditText
style="?CodeFont" // this way you use your custom style
android:id="@+id/txt_username"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
Upvotes: 1