【发布时间】:2015-12-15 04:12:20
【问题描述】:
我想为 LinearLayout 设置可聚焦和可点击的模式(如上图所示)。我怎么做这个?
【问题讨论】:
-
试试这个 myBtn.setFocusableInTouchMode(true);
-
如果你需要更多,那么我会在这里发布 grt answer 以自定义主题等所有内容
-
那是代码行不通
我想为 LinearLayout 设置可聚焦和可点击的模式(如上图所示)。我怎么做这个?
【问题讨论】:
试试这个,它对我有用
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground">
</LinearLayout>
【讨论】:
在您定义的 XML 文件中,您可以在元素中包含:
android:focusable="true"
或
android:clickable="true"
【讨论】: