【问题标题】:Android How to LinearLayout (or other views) set clickable and focusableAndroid 如何将 LinearLayout(或其他视图)设置为可点击和可聚焦
【发布时间】:2015-12-15 04:12:20
【问题描述】:

我想为 LinearLayout 设置可聚焦和可点击的模式(如上图所示)。我怎么做这个?

【问题讨论】:

  • 试试这个 myBtn.setFocusableInTouchMode(true);
  • 如果你需要更多,那么我会在这里发布 grt answer 以自定义主题等所有内容
  • 那是代码行不通

标签: java android focusable


【解决方案1】:

试试这个,它对我有用

<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>

【讨论】:

    【解决方案2】:

    在您定义的 XML 文件中,您可以在元素中包含:

    android:focusable="true"

    android:clickable="true"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 2019-02-27
      • 1970-01-01
      相关资源
      最近更新 更多