Android defines the use of rectangles and selector, shape

Source: Internet
Author: User

"Declaration" reproduced please indicate the source. This article from the tip of the blog: http://blog.csdn.net/huntersnail

--Write a blog every day. Do a little technical accumulation every day!


Android defines the use of rectangles and selector, shape

Because the project development needs, once used selector, shape but have not been well researched, just know how to use. Do not know what their properties are in detail.

Even though you know it on the Internet, it's a good idea to find out for yourself.

Let's look at the following together:


One, XML layout file

/Test Demo/res/layout/check_box.xml

<?

XML version= "1.0" encoding= "Utf-8"?

><linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "Match_ Parent "android:layout_height=" match_parent "android:orientation=" vertical "> <linearlayout android: Id= "@+id/order_meth" style= "@style/style_padding" android:layout_width= "Match_parent" Android:layout_ height= "Wrap_content" android:layout_gravity= "center_vertical" android:background= "@drawable/selector_mine" android:orientation= "Horizontal" > <textview android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:text= "delivery Mode" android:textsize= "18sp"/> <r Adiogroup android:id= "@+id/type" android:layout_width= "Match_parent" Android:layout_heigh t= "wrap_content" android:gravity= "center" android:orientation= "Horizontal" > <radio Button Android:id= "@+id/rb_one "android:layout_width=" wrap_content "android:layout_height=" Wrap_content " style= "@style/sku_rd" android:layout_marginleft= "20DP" android:gravity= "center" Android:checked= "true" android:padding= "10DP" android:text= "one hour Up"/> <radiobutton android:id= "@+id/rb_two" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" style= "@style/sku_rd" android:layout_marginleft= "10DP "android:gravity=" center "android:padding=" 10DP "android:text=" scheduled delivery "/> </RadioGroup> </LinearLayout></LinearLayout>


Second, the background color processing when clicked

1. Style styles

<resources xmlns:android= "Http://schemas.android.com/apk/res/android" >    <style name= "Sku_rd" >        <item name= "Android:textcolor" > @color/selector_text</item>        <item name= "Android: Background "> @drawable/check_boxs</item>        <item name=" Android:button "> @null </item><!- -Remove the RadioButton Circle-    </style></resources>


2, click the RadioButton Border background color transformation of the key XML

Attribute interpretation

"True" indicates the use of a pressed state (such as a button press). "False" indicates a non-pressed state to use.


Android:state_focused= "True/false"

"True" indicates that the focus state is used (such as using a rolling ball/d-pad focus button); "False" indicates the use of a non-focused state.
Android:state_selected= "True/false"

"True" indicates that the selected state is used (such as tab-Open); "false" indicates a unchecked state.
Android:state_active= "True/false"

"True" indicates that the status can be checked and "false" means that it is not available for tick status.

(It is only possible to toggle the optional-non-tick widget for practical use.) )
Android:state_checkable= "True/false"

"True" indicates that the check status is used. "False" indicates a non-checked state use.
Android:state_checked= "True/false"

True "indicates that the check status is used;" false "indicates non-tick status.


Android:state_enabled= "True/false"

"True" indicates the usable state is used (can receive touch/click events). "False" indicates an unavailable state to use.


Android:state_window_focused= "True/false"

"True" indicates that the application form has the focus when used (the application is in the foreground); "false" means that there is no focus when used (such as Notification Bar drop or dialog box display).


/Test Demo/res/drawable/check_boxs.xml

<?

XML version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "Http://schemas.android.com/apk/res/android" > <item android:state_checked= "true" android:drawable= "@drawable/shape_sku" ></item> < Item android:state_pressed= "True" android:drawable= "@drawable/shape_sku" ></item> <item android: State_selected= "true" android:drawable= "@drawable/shape_sku" ></item> <item android:drawable= "@ Drawable/shape_sku_normal "></item></selector>


3. Change of text color

/Test Demo/res/color/selector_text.xml

<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android >    <!--text When selected background--    <item android:state_focused= "true" android:color= "#DB251F"/>    <!--text Click Background--    <item android:state_pressed= "true" android:color= "#DB251F"/>    <item Android:state_checked= "true" android:color= "#DB251F"/>    <item android:state_selected= "true" Android: Color= "#DB251F"/>    <!--text default background--    <item android:color= "#969696"/></selector>


Three, the following is the definition of their own two rectangles

Attribute interpretation

Corners: Rounded Corners

The Android:radius is the radian of the angle, and the larger the value the greater the rounded.
We are also able to set the four corners to a different angle. Set five properties at the same time. The RADIUS attribute is invalid
android:radius= "20DP" sets the radius of Four Corners
android:topleftradius= "20DP" sets the radius of the upper-left corner
Android:toprightradius= "20DP" set the radius of the upper-right corner
android:bottomleftradius= "20DP" setting the radius of the lower right corner
Android:bottomrightradius= "20DP" set the radius of the lower left corner


Stroke: Stroke
Android:width= the width of the "2DP" stroke

The color of the android:color stroke.


We can also make the stroke into a dashed line, set in the following way:
Android:dashwidth= "5DP"
android:dashgap= "3DP"
The android:dashwidth means '-' the width of a horizontal line, Android:dashgap represents the distance between them.


Solid: Fill
ANDROID:COLOR Specifies the color of the fill


/Test Demo/res/drawable/shape_sku_normal.xml

<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" >    <stroke android:width= "1DP" android:color= "#C8C8C8"/>    <corners android:radius= "3DP"/>    <solid android:color= "@android: Color/white"/></shape>
/Test Demo/res/drawable/shape_sku.xml
<?

XML version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" > <stroke android:width= "1DP" android:color= "#DB251F"/> <corners android:radius= "3DP"/> <solid android:color= "@android: Color/white"/></shape>


Four,

Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center ">

Five, source code address Click to open link


☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆ Reprint Please indicate the source? A blog ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆ with your fingertips

Android defines the use of rectangles and selector, shape

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.