简体   繁体   中英

Android Action Bar Set-Up w/ icons

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;
}

}

R.menu.menu应该是R.menu.actionbar,假设在res中有一个名为“ menu”的文件夹,其中放置了actionbar.xml。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM