Android 单击TextView或LinearLayout时如何突出显示它?
我有一个包含三个文本视图的线性布局。我想在用户单击TextView时突出显示TextView或整个布局。他们有什么办法让它发生吗Android 单击TextView或LinearLayout时如何突出显示它?,android,Android,我有一个包含三个文本视图的线性布局。我想在用户单击TextView时突出显示TextView或整个布局。他们有什么办法让它发生吗 谢谢。有很多方法可以做到这一点 最简单的方法是使用各种属性,如android:focusable,android:focusableInTouchMode,android:clickable,以及android:selectAllOnFocus等属性 您还可以通过将视图的背景设置为s来自定义视图的外观(也称为s)。我无法使用Roman的方法,但找到了我的答案。使用XM
谢谢。有很多方法可以做到这一点 最简单的方法是使用各种属性,如
android:focusable
,android:focusableInTouchMode
,android:clickable
,以及android:selectAllOnFocus
等属性
您还可以通过将视图的背景设置为s来自定义视图的外观(也称为s)。我无法使用Roman的方法,但找到了我的答案。使用XML资源作为背景绘图,瞧!它工作起来很有魅力。我支持第2版的布局
<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(...);
...
findviewbyd(R.id.root).setOnClickListener(…);
您对selectableItemBackground的提示对我来说非常有用。应该是公认的答案!