Set XML layout directly:
<Textview
Android: Id = "@ + ID/text_view"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_marginleft = "20sp"
Android: layout_marginright = "20sp"
Android: textstyle = "bold"
Android: Background = "@ drawable/XQ"
Android: textsize = "20sp"/>
Set attributes using XML files
Styles. xml:
<Resources>
<! --
Base application theme, dependent on API level. This theme is replaced
By appbasetheme from Res/Values-vxx/styles. xml on newer devices.
-->
<Style name = "appbasetheme" parent = "Android: theme. Light">
<! --
Theme customizations available in newer API levels can go in
Res/Values-vxx/styles. XML, while customizations related
Backward-compatibility can go here.
-->
</Style>
<! -- Application theme. -->
<Style name = "apptheme" parent = "appbasetheme">
<! -- All mizmizations that are not specific to a special API-level can go here. -->
</Style>
<Style name = "textview">
<Item name = "Android: layout_width"> wrap_content </item>
<Item name = "Android: layout_height"> wrap_content </item>
<Item name = "Android: layout_marginleft"> 20sp </item>
<Item name = "Android: textstyle"> bold </item>
<Item name = "Android: layout_marginright"> 20sp </item>
<Item name = "Android: background"> @ drawable/XQ </item>
<Item name = "Android: textcolor"> #005 </item>
<Item name = "Android: shadowcolor"> @ Android: color/Black </item>
<Item name = "Android: shadowradius"> 0.5 </item>
<Item name = "Android: textsize"> 20sp </item>
</Style>
</Resources>
Layout. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Xmlns: Tools = "http://schemas.android.com/tools"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: Orientation = "horizontal">
<Textview
Android: Id = "@ + ID/text_view"
Style = "@ style/textview"/>
</Linearlayout>
Text setting method:
Textview mytext = (textview) findviewbyid (R. Id. text_view );
Mytext. settext ("CCC ");
How to set the background image:
Textview mytext = (textview) findviewbyid (R. Id. text_view );
Resources resources = getbasecontext (). getresources ();
Drawable = resources. getdrawable (R. drawable. xq1 );
Mytext. setbackgrounddrawable (drawable );