- Forum posts: 1
Apr 13, 2014, 2:42:55 AM via Website
Apr 13, 2014 2:42:55 AM via Website
Here is my code -
main.xml(res/menu/main.xml) -
2 tools:context="com.example.myapplication3.app.MainActivity" >
3
4 <!-- Search, should appear as action button -->
5 <item android:id="@+id/action_search"
6 android:icon="@drawable/ic_action_search"
7 android:title="@string/action_search"
8 android:showAsAction="ifRoom" />
9 <!-- Settings, should always be in the overflow -->
10 <item android:id="@+id/action_settings"
11 android:title="@string/action_settings"
12 android:showAsAction="never" />
13</menu>
MainActivity - (src/java/MainActivity.) -
2
3import android.support.v7.app.ActionBarActivity;
4import android.os.Bundle;
5import android.view.Menu;
6import android.view.MenuItem;
7
8public class MainActivity extends ActionBarActivity {
9
10 @Override
11 protected void onCreate(Bundle savedInstanceState) {
12 super.onCreate(savedInstanceState);
13 setContentView(R.layout.activity_main);
14 }
15
16
17
18
19 @Override
20 public boolean onCreateOptionsMenu(Menu menu) {
21
22 // Inflate the menu; this adds items to the action bar if it is present.
23 getMenuInflater().inflate(R.menu.main, menu);
24 return true;
25 }
26
27 @Override
28 public boolean onOptionsItemSelected(MenuItem item) {
29 // Handle action bar item clicks here. The action bar will
30 // automatically handle clicks on the Home/Up button, so long
31 // as you specify a parent activity in AndroidManifest.xml.
32 int id = item.getItemId();
33 if (id == R.id.action_settings) {
34 return true;
35 }
36 return super.onOptionsItemSelected(item);
37 }
38
39}
I have the the pics in my drawable folders.