Android implementation of several consecutive side-by TextView click Change background color to reach tab tab bar Toggle Effect

Source: Internet
Author: User
<span id="Label3"></p><p><p>"android implementation of several consecutive side-by TextView Click to change the background color to achieve tab tab bar Toggle effect"</p></p><p><p>The implementation of the component interaction is simple, just like the Tab tab of the navigation bar, when the user clicked on a continuous side of several TextView one of them, to produce a certain interactive effect (background color change, etc.). There are a number of options available for this implementation, which are now implemented through the selector.xml of the Background.</p></p><p><p>The effect is as Follows:</p></p><p><p>A. Initial state:</p></p><p><p></p></p><p><p><br></p></p><p><p>B. When the user clicks TextView 2, but the User's finger has been pressed not to release the state, (pay attention to the interactive design effect!). The background color of TextView 2 turns yellow):</p></p><p><p></p></p><p><p><br></p></p><p><p>C. The state of the User's finger after releasing and leaving the device screen on TextView 2:</p></p><p><p></p></p><p><p><br></p></p><p><p>Now give the full implementation Code.</p></p><p><p>A very simple main activity for testing:</p></p><p><p></p></p><pre class="java" name="code"><pre class="java" name="code">Package Zhangphil.change;import Android.app.activity;import Android.os.bundle;public class Mainactivity extends Activity {@Overrideprotected void onCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main);}}</pre></pre><br><p><p></p></p><p><p></p></p><p><p>The focus is on the property configuration and Selector.xml of TextView in Activity_main.xml.</p></p><p><p>Activity_main.xml:</p></p><p><p></p></p><pre class="html" name="code"><?xml version= "1.0" encoding= "utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "android:layout_width=" fill_parent "android:layout_height=" fill_parent "android:orientation=" Horizontal " > <textview android:layout_width= "match_parent" android:layout_height= "wrap_content" Android : layout_gravity= "center_vertical" android:layout_weight= "1" android:background= "@drawable/selector" A ndroid:clickable= "true" android:focusable= "true" android:focusableintouchmode= "true" android:text= "1" /> <textview android:layout_width= "match_parent" android:layout_height= "wrap_content" Andro id:layout_gravity= "center_vertical" android:layout_weight= "1" android:background= "@drawable/selector" android:clickable= "true" android:focusable= "true" android:focusableintouchmode= "true" android:text= " 2 "/> <textview andRoid:layout_width= "match_parent" android:layout_height= "wrap_content" android:layout_gravity= "center_vertica L "android:layout_weight=" 1 "android:background=" @drawable/selector "android:clickable=" true " android:focusable= "true" android:focusableintouchmode= "true" android:text= "3"/> <textview A Ndroid:layout_width= "match_parent" android:layout_height= "wrap_content" android:layout_gravity= "center_verti Cal "android:layout_weight=" 1 "android:background=" @drawable/selector "android:clickable=" true " android:focusable= "true" android:focusableintouchmode= "true" android:text= "4"/></linearlayout></pre><br><p><p></p></p><p><p></p></p><p><p>Each of the TextView used to set the background selector.xml.</p></p><p><p>Selector.xml:</p></p><p><p></p></p><pre class="html" name="code"><pre class="html" name="code"><?xml version= "1.0" encoding= "utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android "> <item android:drawable=" @drawable/red "android:state_focused=" true "/> <item Android :d rawable= "@drawable/orange" android:state_pressed= "true"/> <item android:drawable= "@drawable/green"/ ></selector></pre></pre><br><p><p></p></p><p><p></p></p><p><p><br></p></p><p><p>The rest is some basic resource files, pictures:</p></p><p><p>Green.png</p></p><p><p></p></p><p><p><br></p></p><p><p>Red.png</p></p><p><p></p></p><p><p><br></p></p><p><p>Orange.png</p></p><p><p></p></p><p><p></p></p><p><p>Android implementation of several consecutive side-by TextView click Change background color to reach tab tab bar Toggle Effect</p></p></span>

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.