日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android中focusable属性的妙用——底层按钮的实现

發布時間:2025/3/21 Android 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android中focusable属性的妙用——底层按钮的实现 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

看到百威啤酒的客戶端主界面的按鈕,感覺比較新奇,先看下圖片:

注意圖中我畫的箭頭,當時鼠標點擊的黑色圈圈的位置,然后按鈕出現了按下的效果(黃色的描邊)

剛開始看到這種效果很是好奇,不知道是怎么實現的,后來仔細一想,應該是整個啤酒罐是一張圖片(ImageView),該圖片是布局在三個按鈕之上,然后就是最關鍵的地方,把圖片設置為不可獲取焦點,也就是android:focusable="false"?,就這樣簡單的一行,就可以搞定了!

為了驗證我的想法,我建了一個工程來做測試,效果如下圖所示:

具體代碼如下:

main.xml:

<?xml?version="1.0"?encoding="utf-8"?>? <RelativeLayout?xmlns:android="http://schemas.android.com/apk/res/android"?android:layout_width="fill_parent"?android:layout_height="fill_parent"?>?<LinearLayout?android:layout_width="match_parent"?android:layout_height="wrap_content"?android:orientation="vertical"?>?<Button?android:layout_width="match_parent"?android:layout_height="wrap_content"?android:layout_margin="10dp"?android:text="button1"?android:background="@drawable/button_selector"?/>????<Button?android:layout_width="match_parent"?android:layout_height="wrap_content"?android:layout_margin="10dp"?android:text="button2"?android:background="@drawable/button_selector"?/>??<Button?android:layout_width="match_parent"?android:layout_height="wrap_content"?android:layout_margin="10dp"?android:text="button3"?android:background="@drawable/button_selector"?/>??</LinearLayout>?<ImageView?android:layout_width="wrap_content"?android:layout_height="wrap_content"?android:src="@drawable/bg2"?android:focusable="false"?/>? </RelativeLayout>

button_selector.xml:

<?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="#8470FF"/>?<!--?描邊?-->?<stroke?android:width="2dp"?android:color="#FFFF00"/>?<!--?圓角?-->?<corners?android:radius="5dp"?/>?<padding?android:left="10dp"?android:top="10dp"?android:right="10dp"?android:bottom="10dp"?/>?</shape>?</item><item>???????<shape>?<!--?實心,即填充?-->?<solid?android:color="#8470FF"/>?<corners?android:radius="5dp"?/>?<padding?android:left="10dp"?android:top="10dp"?android:right="10dp"?android:bottom="10dp"?/>?</shape>?</item>? </selector>

轉載于:https://my.oschina.net/u/1036767/blog/213979

總結

以上是生活随笔為你收集整理的Android中focusable属性的妙用——底层按钮的实现的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。