First, create an xml file. The resource type is drawble and the root element is shape.
I. Custom draw lines
<Shape xmlns: android = "http://schemas.android.com/apk/res/android" android: shape = "line"> <stroke android: width = "1dp" // line width android: color = "#33 ccff" // color android: dashWidth = "2dp" // line segment length of the dotted line android: dashGap = "5dp"/> // Interval Length of the dotted line </shape>
You can use the textview control in the layout xml file to set the background attributes.
Ii. Custom circle
<Shape xmlns: android = "http://schemas.android.com/apk/res/android" android: shape = "oval"> <solid android: color = "#33 ccff"/> <size android: width = "50dp" // circle or elliptical android: height = "50dp"/> </shape>
Use the imageview control in the layout xml file
3. Customize the rectangle
<Shape xmlns: android = "http://schemas.android.com/apk/res/android" android: shape = "rectangle"> <gradient android: angle = "45" // an integer multiple of gradient angle 45 android: centerColor = "#00ff00" // gradient color android: endColor = "# 0000ff" android: startColor = "# ff0000"/> <solid android: color = "#33 ccff"/> // solid color <size android: height = "100dp" android: width = "50dp"/> <corners android: radius = "10dp"/> // rounded corner </shape>
4. Use custom Fonts
Copy the font format file. ttf to the assets Directory, read the font file Typeface. createFromAsset, and set the type setTypeface.
The font in the Code is as follows:
TextView textView = (TextView) findViewById (R. id. textView2); Typeface tf = Typeface. createFromAsset (getAssets (), "fonts/samplefont. ttf "); // read the text textView. setTypeface (tf); // set the font
This article is from the "wangcuijing" blog, please be sure to keep this source http://wangcuijing.blog.51cto.com/7233352/1286598