2012-08-27 61 views
2

我是Android新世界。直到現在每一個「OptionsMenu」可以這樣創建:安卓工具缺少硬件選項菜單按鈕

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    getMenuInflater().inflate(R.menu.activity_list_view_controller, menu); 
    return true; 
} 
@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle item selection 
     switch (item.getItemId()) { 
      case R.id.menu_settings: 
       startActivity(new Intent (ListViewControllerActivity.this, PreverencesActivity.class)); 
       return true; 
      case R.id.menu_devsettings: 
       startActivity(new Intent (ListViewControllerActivity.this, DevPreferencesActivity.class)); 
       return true; 
      default: 
       return super.onOptionsItemSelected(item); 
     } 
} 

但現在,例如,新的HTC One沒有硬件OptionsMenu按鈕。當OptionsMenu像我的源一樣實現時,顯示內的menubutton將不會顯示出來。 如何實現OptionsMenu的權利,在佈局中不需要額外的按鈕? 或者顯示器內的這個按鈕是否可以被激活?

編輯: 我覺得我給解決問題,因爲Android將不會照顧它的API 16果凍豆少一點信息。 再次。我已經實現了上面的選項菜單。但現在使用沒有硬件選項菜單按鈕的「htc one」,屏幕上的選項菜單按鈕不會顯示出來。

這裏是我的佈局XML,我使用的(這可能是一個佈局的問題):

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <ImageView 
     android:id="@+id/img_logo" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" /> 

    <TextView 
     android:id="@+id/txt_title" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:background="#1e4870" 
     android:textColor="#ffffff" 
     android:layout_below="@+id/img_logo"/> 

    <ListView 
     android:id="@android:id/list" 
     android:layout_below="@+id/txt_title" 
     android:layout_above="@+id/img_bottom_bar" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 
    </ListView> 

    <ImageView 
     android:id="@+id/img_bottom_bar" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/footer" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:background="@android:drawable/bottom_bar" 
     android:src="@android:drawable/bottom_bar" /> 

    <RelativeLayout 
     android:id="@+id/footer" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/footer_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_toLeftOf="@+id/footer_img_bs" 
      android:textAppearance="?android:attr/textAppearanceSmall" /> 

     <ImageView 
      android:id="@+id/footer_img_bs" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentRight="true" 
      android:src="@drawable/ic_launcher" /> 

    </RelativeLayout> 

</RelativeLayout> 

這裏清單的一部分,我認爲會解決這個問題:

<uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="16" /> 

我也多次搜索這個問題。但似乎我是這個問題的唯一人。所以我必須有點愚蠢或什麼。

我忘記之前:謝謝你WebnetMobile.com試圖幫助我。這可能是因爲我只是(就像我之前說過的)太愚蠢,無法理解你的答案。

回答

2

我已經解決了像this鏈接描述的問題。您可以簡單地將「targetSdkVersion」從16更改爲10.

1

你在說關於選項菜單,而不是上下文菜單(上下文菜單是當你即長按列表查看項目)。如果設備沒有菜單按鈕,您就不用擔心。 Android將照顧它爲你,如果你的應用將如蜂窩運行,並且從未使用的Android版本(這滴菜單按鈕),但您的應用程序需要它,Android將顯示屏幕上的菜單按鈕

+2

第一:對不起,您好了,它是一個選項菜單,而不是一個選項菜單* facepalm * 第二:如果我理解你,你的意思是我有沒有什麼可以做,它會工作......但事實並非如此...... –

0

切換在3.0 +在選項菜單

<menu xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:id="@+id/menu_settings" 
    android:title="@string/menu_settings" 
    android:orderInCategory="100" 
    android:icon="@drawable/ic_action_search" 
    android:showAsAction="ifRoom|withText"/> 
</menu> 

使用菜單XML等,對於兼容性 的情況下的動作杆,使得被點擊菜單按鈕時在3.1- 同時支撐上部verssions 進一步的細節將示出reffer Android開發者網站 http://developer.android.com/guide/topics/ui/actionbar.html