Android LinearLayout and other views how to obtain the button Effect

Source: Internet
Author: User

We can set the View. onClickListener listener for LinearLayout and all controls inherited from the View, such as LInearLayout.

However, we found that LinearLayout can execute the listening method body, but it does not have the effect of clicking.

The so-called click effect is that when we click the control with the mouse, we can highlight or move it to give the user an operation feedback.

How to implement the above effect for LinearLayout is to configure the following attributes for LinearLayout


 

style="?android:attr/actionButtonStyle" style="?android:attr/actionButtonStyle"

Then our buttons have the style effect of the Button. Click and other operations are the same as Button operations.

In addition, we can configure a file, such as the image effect when you click in the file configuration, and the image effect when you press the file, for example:


 

?<selector xmlns:android="http://schemas.android.com/apk/res/android"                                                                      |~                                        android:exitFadeDuration="@android:integer/config_mediumAnimTime">                                                              |~                                                                                                                                                                        |~                                  <!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of      |~                              pressed state. -->                                                                                                                        |~                                  <item android:state_focused="true"  android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/           |~                              list_selector_disabled_holo_dark" />                                                                                                      |~                                  <item android:state_focused="true"  android:state_enabled="false"                              android:drawable="@drawable/           |~                              list_selector_disabled_holo_dark" />                                                                                                      |~                                  <item android:state_focused="true"                                android:state_pressed="true" android:drawable="@drawable/           |~                              list_selector_background_transition_holo_dark" />                                                                                         |~                                  <item android:state_focused="false"                               android:state_pressed="true" android:drawable="@drawable/           |~                              list_selector_background_transition_holo_dark" />                                                                                         |~                                  <item android:state_focused="true"                                                             android:drawable="@drawable/           |~                              list_focused_holo" />                                                                                                                     |~                                  <item                                                                                          android:drawable="@color/transparent" /|~                              >                                                                                                                                         |~                              </selector> <selector xmlns:android="http://schemas.android.com/apk/res/android"                                                                      |~                                      android:exitFadeDuration="@android:integer/config_mediumAnimTime">                                                              |~                                                                                                                                                                      |~                                <!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of      |~                            pressed state. -->                                                                                                                        |~                                <item android:state_focused="true"  android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/           |~                            list_selector_disabled_holo_dark" />                                                                                                      |~                                <item android:state_focused="true"  android:state_enabled="false"                              android:drawable="@drawable/           |~                            list_selector_disabled_holo_dark" />                                                                                                      |~                                <item android:state_focused="true"                                android:state_pressed="true" android:drawable="@drawable/           |~                            list_selector_background_transition_holo_dark" />                                                                                         |~                                <item android:state_focused="false"                               android:state_pressed="true" android:drawable="@drawable/           |~                            list_selector_background_transition_holo_dark" />                                                                                         |~                                <item android:state_focused="true"                                                             android:drawable="@drawable/           |~                            list_focused_holo" />                                                                                                                     |~                                <item                                                                                          android:drawable="@color/transparent" /|~                            >                                                                                                                                         |~                            </selector> 

 

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.