Reputation: 1
I can see in menu design have picture like this
https://i.sstatic.net/WHcFZ.jpg
But when I switch to layout design
https://i.sstatic.net/8NrSO.jpg
I cannot see the menu anymore.
I already check for menu setting
make a onCreateOptionsMenu
set menu/main.xml
xmlns:tools / tools:context
But it still have no menu bar in there. The code is below:
MainActivity.java
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if(id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
Layout/activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.jason.web_control.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/playPauseButton"
android:clickable="true"
android:background="@android:color/holo_blue_dark"
android:id="@+id/mousePad"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</LinearLayout>
menu/menu_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.jason.web_control.MainActivity">
<item
android:id="@+id/action_settings"
android:title="@string/action_settings"
app:showAsAction="always" />
</menu>
Upvotes: 0
Views: 146
Reputation: 65
What I did was
public MoviesFragment() {
setHasOptionsMenu(true);
}
and need to override
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
}
return super.onOptionsItemSelected(item);
}
Upvotes: 0