默認情況下,當您單擊按鈕時,它將突出顯示。當用戶點擊 TextView 時,如何對它做同樣的事情?
uj5u.com熱心網友回復:
您應該能夠通過設定視圖可點擊和foreground正確設定屬性在 xml 布局檔案中設定它。
例如:
...
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:foreground="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
/>
...
請注意,foreground僅適用于 Android API 版本 23 或更高版本。如果您需要在低于該版本的版本中使用它,請替換android:foreground為android:background. 不完全相同的行為(波紋效果放置在文本的背景中,而不是像屬性名稱所示的那樣放置在視圖上方的圖層中),但它應該可以解決問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/381893.html
