如何设置Android ActionBar';以编程方式创建下一个可聚焦控件
我正在为谷歌电视开发一个应用程序,所有的导航都将使用D-Pad/键盘完成 我的活动有一个ActionBar,下面有一些水平的列表。说出列表A、B和C。根据列表A的选定项,列出B&C加载数据。。因此,他们可能/可能不加载数据 问题是,当ActionBar有焦点并且我按下D-Pad键时,焦点会丢失,并且不会转移到列表C(或者B,如果C没有数据)。。是吗 为了实现这一点,我尝试通过编程方式设置ActionBar的下一个可聚焦视图,如下所示如何设置Android ActionBar';以编程方式创建下一个可聚焦控件,android,android-layout,google-tv,android-actionbar,Android,Android Layout,Google Tv,Android Actionbar,我正在为谷歌电视开发一个应用程序,所有的导航都将使用D-Pad/键盘完成 我的活动有一个ActionBar,下面有一些水平的列表。说出列表A、B和C。根据列表A的选定项,列出B&C加载数据。。因此,他们可能/可能不加载数据 问题是,当ActionBar有焦点并且我按下D-Pad键时,焦点会丢失,并且不会转移到列表C(或者B,如果C没有数据)。。是吗 为了实现这一点,我尝试通过编程方式设置ActionBar的下一个可聚焦视图,如下所示 getActionBar().getCustomView().
getActionBar().getCustomView().setNextFocusDownId(R.Id.list_C_id);
但不起作用
我还尝试使用层次查看器检查布局层次结构。。。但是,坦率地说,我不明白如何处理它的发现
如何以编程方式设置Android ActionBar的下一个可聚焦控件
非常感谢您的帮助
活动的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>
每个列表/网格的所有容器都直接或以其样式设置了android:focusable=“true”
编辑:可以从
请将包含在第一个列表中。您可以通过main.xml文件中的idallPackagesList对其进行搜索。我忘了插入它。对不起
此应用程序中的问题有:
列表是否包装在另一个容器中?尝试为列表及其容器添加android:focusable=“true”..它不起作用。。。我已经更新了我的问题并放置了活动的XML。。我可以使用一些带有按钮的自定义标题(用作操作按钮)和用于徽标的图像。。但是我不想。。。因为我想使用内置的ActionBar。请帮我整理一下,因为这很紧急。我在xml中没有看到ListView或ActionBar。ListView和两个GridView在xml中。。。我没有在XML中添加ActionBar。。。我刚刚将主题设置为holo&在OnCreateOptions菜单中为菜单充气。。动作栏出现了。。。我遵循了android ActionBar教程。我很抱歉,如果我错过了一些东西,因为我是AndroidOrry的新手,我在这里无能为力。我试图创建一个项目来重现这个问题,但它是一个非常大的xml文件,我不确定您使用它的方式。如果没有一些简单的源代码可以轻松地重现问题,我很难进行调试。我已经更新了我的问题,并添加了一个示例应用程序的链接。你可以下载它。。。它的XML与我的活动完全相同。。。所以你会确切地知道我面临的问题。。。非常感谢你的帮助