當前我正在使用的應用程序的設計在操作欄上沒有菜單按鈕的空間。有些android設備沒有菜單硬件按鈕,然後我看到一個應用程序,在屏幕上有一個按鈕,我想在應用程序中實現。在屏幕按鈕上添加附加按鈕
我想知道如何添加在屏幕上的按鈕,這個按鈕:
當前我正在使用的應用程序的設計在操作欄上沒有菜單按鈕的空間。有些android設備沒有菜單硬件按鈕,然後我看到一個應用程序,在屏幕上有一個按鈕,我想在應用程序中實現。在屏幕按鈕上添加附加按鈕
我想知道如何添加在屏幕上的按鈕,這個按鈕:
此按鈕取代上沒有物理菜單按鈕,設備硬件菜單按鈕。但只有當應用程序仍然需要使用舊的菜單按鈕時纔會使用它。我強烈建議清理您的操作欄並實施新的設計約定,因爲舊的菜單按鈕已棄用。
您應該閱讀this以熟悉該主題。
您應該在創建新項目時獲得此信息。添加名爲menu
res
文件夾,這個文件夾中添加main.xml
複製粘貼
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.asd.MainActivity" > <!--Change this to your Activity--!>
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never"/>
</menu>
然後在你的活動添加此
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
好像沒有其他辦法,而不是重新設計操作欄,這裏還有一篇關於菜單按鈕的文章:http://android-developers.blogspot.com/2012/01/say-goodbye-to-menu-button.html – 2014-10-09 13:45:37
你是對的。正如文章指出的那樣,這是遺產。也許你應該問StackOverflow如何改進你的設計? – 2014-10-09 13:49:15