您好,登錄后才能下訂單哦!
在Android中,為Button添加觸摸反饋和視覺反饋可以提高用戶體驗(yàn)
例如,創(chuàng)建一個(gè)名為button_touch_feedback.xml
的文件,放在res/drawable
目錄下:
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<solid android:color="#3ddc84"/>
<corners android:radius="4dp"/>
</shape>
</item>
<item>
<shape>
<solid android:color="#2196F3"/>
<corners android:radius="4dp"/>
</shape>
</item>
</selector>
然后,在布局文件中將此背景應(yīng)用到Button上:
android:id="@+id/my_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click me!"
android:background="@drawable/button_touch_feedback"/>
android:stateListAnimator
屬性為按鈕添加動(dòng)畫效果。例如,創(chuàng)建一個(gè)名為button_visual_feedback.xml
的文件,放在res/animator
目錄下:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:propertyName="scaleX"
android:duration="100"
android:valueTo="0.9"
android:valueType="floatType"/>
<objectAnimator
android:propertyName="scaleY"
android:duration="100"
android:valueTo="0.9"
android:valueType="floatType"/>
</set>
然后,在布局文件中將此動(dòng)畫應(yīng)用到Button上:
android:id="@+id/my_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click me!"
android:stateListAnimator="@animator/button_visual_feedback"/>
這樣,當(dāng)用戶點(diǎn)擊按鈕時(shí),按鈕會(huì)縮小一點(diǎn),表示正在處理用戶的操作。你可以根據(jù)需要自定義觸摸反饋和視覺反饋的效果。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。