gpt4 book ai didi

android - 如何以编程方式设置 Android ActionBar 的下一个可聚焦控件

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:29:32 25 4
gpt4 key购买 nike

我正在为 Google TV 开发一个应用程序,其中所有导航都将使用方向键/键盘完成。

我的 Activity 有一个 ActionBar 和一些水平放置在其下方的列表。说列表 A、B 和 C。列表 B & C 根据列表 A 的选定项目加载数据.. 因此它们可能/可能不会加载数据。

问题是当 ActionBar 有焦点并且我按下 D-Pad DOWN 键时,焦点丢失并且不会转移到列表 C(或 B 如果 C 没有数据 ) .. y?

为了实现这一点,我尝试像下面这样以编程方式设置 ActionBar 的下一个可聚焦 View

getActionBar().getCustomView().setNextFocusDownId(R.Id.list_C_id);

但没用。

我还尝试使用 Hierarchy Viewer 检查布局层次结构......但是,坦率地说,我不明白如何处理它的发现。

如何以编程方式设置 Android ActionBar 的下一个可聚焦控件??

非常感谢任何帮助。

Activity 的 XML 如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainContainer" style="@style/main" >

<!-- Splash Screen -->
<LinearLayout
android:id="@+id/splash_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/welcome"
android:orientation="vertical" >
</LinearLayout>

<!-- main content holder.. it is shown afetr some time of showing above splash screen -->
<LinearLayout
android:id="@+id/main_content_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:focusable="true"
android:visibility="invisible">

<!-- All Packages List -->

<LinearLayout
android:layout_width="205dp"
android:layout_height="match_parent"
android:background="@drawable/content_round_bg"
android:focusable="true"
android:orientation="vertical" >

<!-- Header of Packages-->
<RelativeLayout
style="@style/marginLeft5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/content_round_bg" >

<ImageView
android:id="@+id/packagesIcon"
style="@style/titleIcon"
android:src="@drawable/packages" >
</ImageView>

<TextView
style="@style/title"
android:layout_toRightOf="@+id/packagesIcon"
android:text="Packages" >
</TextView>

<ProgressBar
android:id="@+id/progressBarPackages"
style="@style/progressBar" />
</RelativeLayout>

<!-- <View style="@style/horizontalSeperator" /> -->

<ListView
android:id="@+id/allPackagesList"
style="@style/list"
android:nextFocusRight="@+id/gridChannels">
</ListView>

<!-- Message which is hidden by default and is made visible if list has no data -->
<LinearLayout
android:id="@+id/packageNotFound"
style="@style/emptyListIdentifier" >

<ImageView
style="@style/titleIcon"
android:src="@drawable/info" >
</ImageView>

<TextView
style="@style/emptyListIdentifierText"
android:layout_marginLeft="5dp"
android:text="Packages not available" >
</TextView>
</LinearLayout>
</LinearLayout>

<View style="@style/verticalSeperator" />

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:focusable="true"
android:orientation="vertical" >

<LinearLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:layout_below="@+id/titleContainer" >

<LinearLayout
android:id="@+id/channelsContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.35"
android:background="@drawable/content_round_bg"
android:focusable="true"
android:orientation="vertical" >

<!-- Header of Channels-->
<RelativeLayout
style="@style/marginLeft5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/content_round_bg" >

<ImageView
android:id="@+id/channelsIcon"
style="@style/titleIcon"
android:src="@drawable/channels" >
</ImageView>

<TextView
style="@style/title"
android:layout_toRightOf="@+id/channelsIcon"
android:text="Channels" >
</TextView>

<ProgressBar
android:id="@+id/progressBarChannels"
style="@style/progressBar" />
</RelativeLayout>

<RelativeLayout style="@style/listsContiner" android:focusable="true" >

<GridView
android:id="@+id/gridChannels"
style="@style/grid"
android:divider="#10F1F1F1"
android:nextFocusLeft="@+id/allPackagesList"
android:nextFocusRight="@+id/gridAllVODs"
android:numColumns="2" />
</RelativeLayout>

<!-- Message which is hidden by default and is made visible if list has no data -->
<RelativeLayout
android:id="@+id/channelsNotFound"
style="@style/emptyListIdentifier" >

<ImageView
android:id="@+id/NoChannelsIcon"
style="@style/titleIcon"
android:src="@drawable/info" >
</ImageView>

<TextView
style="@style/emptyListIdentifierText"
android:layout_toRightOf="@+id/NoChannelsIcon"
android:text="Channels are currently not available" >
</TextView>
</RelativeLayout>
</LinearLayout>

<View style="@style/verticalSeperator" />

<LinearLayout
android:id="@+id/vodsContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.65"
android:background="@drawable/content_round_bg"
android:orientation="vertical" >

<!-- Header of VODs-->
<RelativeLayout
style="@style/marginLeft5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/content_round_bg" >

<ImageView
android:id="@+id/VODsIcon"
style="@style/titleIcon"
android:src="@drawable/vod" >
</ImageView>

<TextView
style="@style/title"
android:layout_toRightOf="@+id/VODsIcon"
android:text="VOD" >
</TextView>

<ProgressBar
android:id="@+id/progressBarVODs"
style="@style/progressBar" />
</RelativeLayout>

<RelativeLayout style="@style/listsContiner" >
<GridView
android:id="@+id/gridAllVODs"
style="@style/grid"
android:divider="#10F1F1F1"
android:nextFocusLeft="@+id/gridChannels"
android:nextFocusRight="@+id/allPackagesList"
android:numColumns="1" />
</RelativeLayout>

<!-- Message which is hidden by default and is made visible if list has no data -->

<RelativeLayout
android:id="@+id/videosNotFound"
style="@style/emptyListIdentifier" >

<ImageView
android:id="@+id/NoVODsIcon"
style="@style/titleIcon"
android:src="@drawable/info" >
</ImageView>

<TextView
style="@style/emptyListIdentifierText"
android:layout_centerInParent="true"
android:layout_toRightOf="@+id/NoVODsIcon"
android:text="Videos are currently not available" >
</TextView>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>

每个 List/Grid 的所有容器到 Top most LinearLayout 都直接或在其样式中设置了 android:focusable="true"。

编辑可以从 here 下载准确描述我的 spp 屏幕的示例应用程序

请在第一个列表中包含。您可以在 main.xml 文件中通过其 ID allPackagesList 搜索它。我忘了插入它。抱歉

此应用中的问题是:

  1. 焦点没有从 ActionBar 项目到达列表/网格。
  2. 在 ActionBar 项之间导航需要多次按下方向键“向左”或“向右”来移动

最佳答案

List 是否包裹在另一个容器中?尝试为您的列表及其容器添加 android:focusable="true"..

关于android - 如何以编程方式设置 Android ActionBar 的下一个可聚焦控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9239414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com