Using shape and selector to achieve click effect, shapeselector

Source: Internet
Author: User

Using shape and selector to achieve click effect, shapeselector

<Span style = "font-family: Arial, Helvetica, sans-serif; font-size: 18px; background-color: rgb (255,255,255);"> sometimes it is easy for us, if you don't want to give us images, you can't do it or offend the artist. But we can use colors to achieve our click effect! </Span>

<span style="font-family: Arial, Helvetica, sans-serif;"><?xml version="1.0" encoding="UTF-8"?></span><shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="rectangle" >    <gradient        android:angle="90"        android:endColor="#ffff99"        android:startColor="#ffff99" />    <corners android:radius="20dp" /></shape>


<?xml version="1.0" encoding="UTF-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="rectangle" >    <gradient        android:angle="90"        android:endColor="#cc3935"        android:startColor="#cc3935" />    <corners android:radius="20dp" /></shape>
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:drawable="@drawable/red_shape" android:state_pressed="true"/>    <item android:drawable="@drawable/gray_shape"/></selector>
Do it yourself !!!!!!!!!!


Android uses selector to implement imageview. The default value is gray. After being clicked, it turns blue and remains blue.

<? Xml version = "1.0" encoding = "UTF-8"?>
<Selector xmlns: android = "schemas.android.com/apk/res/android">
<Item android: state_pressed = "true" android: drawable = "@ drawable/appreciate_challenge_select"/> <! -- Pressed -->
<Item android: drawable = "@ drawable/appreciate_challenge_default"/> <! -- Default -->
</Selector>

To keep a color, you can set it after clicking

In android ListView, You need to click a certain part of the content. The clicking effect is implemented by selector, but clicking other parts in ListView also works.

Generally, the clicking effect of a single view is placed on the button.
If there is a button in the item, it will cause the focus issue. You need to control it through android: descendantFocusability = "blocksDescendants ".
In this way, you can achieve your effect.

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.