ÉèÖõã»÷Ч¹ûforeground

ditclear / ÎÄ ·¢±íÓÚ2017-10-29 02:26 µÚ´ÎÔĶÁ

android:foreground

×î½üÒ»¶Îʱ¼äÑо¿ÁËÒ»ÏÂplaid£¬ÏëѧϰһÏÂmaterial design¡£

ÕâÀï¼Ç¼һÏÂviewµÄbackgroundºÍforeground¡£

ƽʱµÄ»°ÎÒÃÇÉèÖõã»÷Ч¹û£¬ÎªÁ˼ò±ã£¬´ó¶àÊýÈËÓ¦¸Ã¶¼»áʹÓÃ

android:background="@drawable/selecterDrawable"
//»òÊÇ
android:background="?selectableItemBackground"

µ«ÊÇÏàÐŶ¼×¢Òâµ½Ò»¸öÇé¿ö£¬¾ÍÊÇÔÚÓÐImageViewµÄʱºò£¬µã»÷Ч¹ûÎÞ·¨äÖȾÔÚImageViewÉÏÃæ

ÔÚ¿´plaidºÍmedium appµÄʱºò·¢ÏÖËüÃǵĵã»÷Ч¹û¾ÍºÜºÃ£¬¿´ÁËplaidµÄxml·¢ÏÖÊÇÉèÖÃÁËforeground

ËùÒÔ°ÂÃØ¾ÍÔÚÕâÀÒÔºóÉèÖõã»÷Ч¹ûµÄ»°¿ÉÒÔÉèÖÃforeground

<FrameLayout
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_gravity="center"
            android:clickable="true"
            android:foreground="@drawable/middle_grey"
            android:padding="@dimen/activity_vertical_margin"
            android:stateListAnimator="@animator/anim_rise">
        <android.support.v7.widget.AppCompatImageView
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="50dp"
                android:scaleType="fitCenter"
                app:srcCompat="@drawable/image"/>
        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical|right"
                android:text="foreground"/>
    </FrameLayout>

ÒòΪapi 21ÒÔÉϲÅÄÜʹÓÃrippleЧ¹û£¬ËùÒÔ×îºÃÇø·ÖÒÔÏÂ

api21ÒÔϵÄmiddle_grey¼°Ð§¹û

<?xml version="1.0" encoding="utf-8"?>
<selector  xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="false">
        <color android:color="@android:color/transparent"/>
    </item>
    <item android:state_pressed="true">
        <color android:color="@color/mid_grey"/>
    </item>
</selector>

<21

api21ÒÔÉϵÄmiddle_grey

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="@color/mid_grey">
</ripple>

21ÒÔÉÏ

¿ÉÒÔ¿´³öЧ¹ûÒªºÃºÜ¶à

ÏÞÖÆ: ÏëҪȷ±£ÓÐÒÔÉÏЧ¹ûÐèҪעÒ⼸µã

  1. È·±£viewÊÇ¿ÉÒÔµã»÷µÄ£¨¼´ÓÐclickʼþ»òÕßclickable="true"£©
  2. È·±£°²×¿°æ±¾ÔÚ6.0£¨M£©¼°ÒÔÉÏ»òÕßÒÔFrameLayout±¾Éí¼°Æä×ÓÀà×÷ΪÈÝÆ÷

¸½Ôù£º

AS¿ìËÙµ¼º½menuµÄicon

icon Æäʵƽʱһֱ¶¼Ã»×¢Òâ¹ý£¬ºóÀ´forkÁËÕâ¸öÏîÄ¿µÄʱºòͻȻ³öÏÖÁËÒ»¸öСͼ±ê£¬²Å·¢ÏÖÕâÒ»µã£¬¸Ð¾õͦ²»´íµÄ¡£

½²Ò»ÏÂÔõô¼òµ¥ÉèÖÃicon

change_icon ÔÚÏîÄ¿ÉÏÓÒ¼ü£¬µã»÷Change IconÑ¡Ôñ×Ô¼ºµÄicon¾ÍºÃÁË

GIPHY CAPTURE : ¼ÆÁ GIF

ÍÆ¼öÒ»ÏÂÕâ¿îmacÉϵļÆÁÈí¼þ£¬·Ç³£ÊµÓöøÇÒÑÕÖµÂù¸ß£¬¸öÈ˾õµÃ±ÈLICEcap¸üºÃ¡£

Â¼ÖÆÍê³ÉÖ®ºó£¬ÄãÄܼòµ¥¼ô¼­ GIF ºÍÑ¡Ôñ²¥·ÅËÙ¶È¡¢´óС¡£

¿ÉÒÔ¿´ÕâÀïÁ˽â¸ü¶à