Reputation: 2448
I want to include a menu in my activity, now it has just one item for help with an icon and a text, the showAsAction is set to ifRoom but it is always shown in the action overflow. Why I don't get juste the drawable?
Here is the 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.mycompany.myapp.Mymainclass" >
<item
android:id="@+id/help"
android:orderInCategory="100"
android:title="@string/help"
android:icon="@drawable/ic_help"
app:showAsAction="ifRoom"/>
</menu>
The MainActivity:
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Base64;
import android.view.Menu;
public class MainActivity extends FragmentActivity {
SharedPreferences prefs;
Menu menu;
@Override
public void onCreate(Bundle save){
super.onCreate(save);
setContentView(R.layout.pokemons_layout);
prefs = getSharedPreferences("PREFERENCES", Context.MODE_PRIVATE);
if (findViewById(R.id.fragment_container) != null) {
if (save != null) {
return;
}
CustomListFragment listFragment = new CustomListFragment();
listFragment.setArguments(getIntent().getExtras());
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_container, listFragment).commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
this.menu = menu;
getMenuInflater().inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public void onPause(){
super.onPause();
String bytearray = Base64.encodeToString(DB.bytearray, Base64.DEFAULT);
prefs.edit().putString("BYTEARRAY", bytearray).apply();
}
@Override
public void onResume(){
super.onResume();
String bytearray = prefs.getString("BYTEARRAY", Base64.encodeToString(DB.bytearray, Base64.DEFAULT));
DB.bytearray = Base64.decode(bytearray, Base64.DEFAULT);
}
}
Upvotes: 0
Views: 76
Reputation: 333
try this because not all apps use the appcompat support lib
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/menu_add_size"
android:title="@string/menu_add_item"
android:orderInCategory="100"
android:showAsAction="always"
android:icon="@android:drawable/ic_menu_add" />
</menu>
Upvotes: 1