2012-02-11 66 views
5

我正在開發Google TV應用程序,其中將使用D-Pad /鍵盤完成所有導航。如何以編程方式設置Android ActionBar的下一個可對焦控件

我的活動有一個ActionBar和水平下面的幾個列表。說清單A,B & C。列表B & C基於所選項目清單A加載數據。因此他們可能會/可能不會加載數據。

問題是,當動作條具有焦點和我按DOWN d-墊鍵時,焦點將丟失,而不是轉移到列表Ç(或如果Ç沒有數據).. Y'

要做到這一點,我試圖以編程方式設置ActionBar的下一個可選擇的觀點類似以下

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

,但沒有奏效。

我也嘗試使用Hierarchy Viewer檢查佈局層次結構......但坦率地說,我不明白如何處理它的發現。

如何以編程方式設置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> 

所有各表的集裝箱/網格高達最頂端的LinearLayout已設置機器人:可調焦=「真」或直接在它的風格。

編輯:準確描述我屬的屏幕示例應用程序可以從here

下載,請在第一個列表。您可以在main.xml文件中通過其編號allPackagesList進行搜索。我忘了插入它。抱歉,在此應用程序

的問題是:

  1. Focus不來了,從動作條項目列表/網格。
  2. 動作條項目之間的導航需要一個以上的d-墊「左」或「右」按下移動

回答

0

被包裹另一個容器內的名單?嘗試爲您的列表及其容器添加android:focusable =「true」..

+0

它沒有工作......我更新了我的問題並放置了活動的XML ..我可以使用一些自定義標題和按鈕作爲行動按鈕)和圖像的徽標..但我不想...因爲我想使用內置的ActionBar。請幫我整理一下,因爲這是非常緊急的 – Aamir 2012-02-13 11:12:41

+0

我沒有看到xml中的ListView或ActionBar。 – 2012-02-13 21:17:33

+0

ListView和兩個GridView在xml中存在...並且我沒有在XML中添加ActionBar ...我只是在onCreateOptionsMenu中設置了主題以全息和充氣菜單..並且出現了ActionBar ...我遵循了Android ActionBar教程來自http://developer.android.com/guide/topics/ui/actionbar.html。我很抱歉,如果我錯過了一些東西,因爲我是新的android – Aamir 2012-02-13 22:10:23

相關問題