The R.menu.menu should be R.menu.actionbar, assuming that in res you have a folder named "menu" in which you put the actionbar.xml.
Android Action Bar Set-Up w/ icons
-
06-07-2023 - |
سؤال
I've been trying to get a standard action Bar to be set up for ages now for 4.4, but I can't seem to grasp the concept of it. I've tried several tutorials and I can never seem to compile it.
I just want the action bar to function. So the action bar could use icons or text - so how do I properly use the android icon pack?
How do I properly call the actionbar menu xml and run any form of action-bar?
This is my actionbar.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_refresh"
android:orderInCategory="100"
android:showAsAction="always"
android:icon="@drawable/ic_action_refresh"
android:title="Refresh"/>
<item
android:id="@+id/action_settings"
android:title="Settings"
android:showAsAction="ifRoom"
</item>
</menu>
mainactivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@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);
// inflater.inflate(R.menu.main, menu);
return true;
}
}
المحلول
لا تنتمي إلى StackOverflow