-1
私のアプリケーションバーにメニューのXMLファイルを表示する方法を見つけようとしているので、私は助けを求めています。アプリケーションバー(メニュー)xmlファイルを表示するには
メインの活動のxml:
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
android:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
主な活動のJava:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
}
とメニューフォルダ内のxmlファイルを
これは私がこれまで持っているものです。
現時点でアプリケーションバーに表示されている唯一のものは、アプリケーション名です。(また、表示されていない設定項目があるはずです)
私はどこのxmlどこを尊敬する必要がありますかファイルは、別のXMLファイルを編集する必要がありますか?それとも完全に何かを逃しているのですか?
私は、このガイドの手順に従っ:https://developer.android.com/training/appbar/setting-up.html
あなたは、私が質問してください行方不明ですどんな情報が必要な場合。ご協力ありがとうございました。
@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_activity_actions, 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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
: