I'm building an app with AndroidStudio. I want to display an ActionBar in my application.
I want to add a menu into my AppCompactActivity. This is the menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Search, should appear as action button -->
<item android:id="@+id/action_search"
android:icon="@android:drawable/ic_menu_save"
android:showAsAction="always"
android:title="Salva"/>
</menu>
This is the layout that I can see from Android Studio preview.
This is my AppCompactActivity:
public class setting extends AppCompatActivity{
public Program program;
public TextView textTargetUri;
public TextView labelUrl;
public ImageView targetImage;
private static final int SELECT_PICTURE = 1;
private String selectedImagePath;
private ImageView img;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.setting);
img = (ImageView)findViewById(R.id.ImageView01);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_setting, menu);
return super.onCreateOptionsMenu(menu);
}
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.action_search:
getSchermataHome();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
But this is the layou that I can see:
How can I fixed it?
ActionBar
in anAppCompatActivity
is actually aToolbar
underneath, so just follow the accepted answer on the linked duplicate.