android - FrameLayout 无法通过按键获取焦点?

标签 android focus android-framelayout

我有一个 View (假设它是 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>

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

最佳答案

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

boolean b = yourLayout.requestFocus();

这将返回是否获得焦点。

关于android - FrameLayout 无法通过按键获取焦点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28233840/

相关文章:

ide - Xcode 4.0.2/4A2002a : Editor > Code Folding -> Focus follows selection: Grey/Disabled. 为什么?

android - 如何以编程方式创建带有 id 和 src 参数的 imageView?

android - 内容提供者和内容观察者示例?

android - 折叠工具栏向上滚动时隐藏,向下滚动时显示

java - TimePickerDialog 不会显示

javascript - 为什么 CurrencyTextField 中的 inputRef 返回错误 inputRef.current is null?

android - 针对 Eclipse 和 Android Studio 的 OSMAnd Android 编译

javascript - 从窗口外返回时出现模糊和焦点问题

android - fragment 在 ViewPager 中无法正确显示

java - 如何在 FrameLayout android 中为 ImageView 添加边距?