我有一个包含三个TextView的LinearLayout。我想在用户点击TextView时突出显示TextView或整个布局。他们是否有办法实现这一目标?
感谢。
答案 0 :(得分:14)
我supperpose 2 Layout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
>
<LinearLayout
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
>
...
</LinearLayout>
</LinearLayout>
findViewById(R.id.root).setOnClickListener(...);
答案 1 :(得分:7)
我无法让罗曼的方法奏效,但我找到了答案here。使用XML资源作为背景drawable和瞧!它就像一个魅力。
答案 2 :(得分:3)