【问题标题】:FrameLayout can not get focus with key press?FrameLayout无法通过按键获得焦点?
【发布时间】:2015-03-29 19:23:12
【问题描述】:

我有一个视图(假设是MyFramLayout)扩展了FrameLayout,我无法在按键时获得这个FrameLayout获得焦点(我在电视平台工作)。

布局是这样的:

<LinearLayout android:layout_width="match_parent"
              android:layout_height="match_parent">

    <ListView android:id="@android:id/list"
              android:layout_width="match_parent"
              android:layout_height="wrap_content" />

    <com.roger.MyFrameLayout 
              android:id="@android:id/my_frame"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:focusable="true"
              android:focusableInTouchMode="true" />

</LinearLayout>

无论如何要解决这个问题?

【问题讨论】:

  • link 的答案,也许用FrameLayout 替换EditText 可以。

标签: android focus android-framelayout


【解决方案1】:

当您希望自定义布局获得焦点时,您必须调用

boolean b = yourLayout.requestFocus();

这将返回是否获得焦点。

【讨论】:

    猜你喜欢
    • 2021-10-26
    • 1970-01-01
    • 1970-01-01
    • 2020-09-16
    • 1970-01-01
    • 2016-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多