View difference between Paste ID: u42j189y and xqnrcJvt
SHOW: | | - or go back to the newest paste.
1
public class SecondActivity extends Activity {
2
3
	private static final String TAG = SecondActivity.class.getName();
4
5
	public SecondActivity() {
6
	}
7
8
	@Override
9
	protected void onCreate(Bundle savedInstanceState) {
10
		super.onCreate(savedInstanceState);
11
		init();
12
	}
13
14
	private void init() {
15
		View  contentView = getContentView();
16
        setContentView(contentView);
17
        LinearLayout layout = (LinearLayout) contentView.getParent().getParent();
18
        View view = layout.getChildAt(0);
19
        layout.removeViewAt(0);
20
        layout.addView(view);
21
        
22
		ActionBar actionBar = getActionBar();
23
		actionBar.setTitle("ActionBar");
24
		actionBar.setDisplayHomeAsUpEnabled(true);
25
		actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
26
	}
27
28
	@Override
29
	public void onCreateContextMenu(ContextMenu menu, View v,
30
			ContextMenuInfo menuInfo) {
31
		super.onCreateContextMenu(menu, v, menuInfo);
32
	}
33
34
	@Override
35
	public boolean onCreateOptionsMenu(Menu menu) {
36
		getMenuInflater().inflate(R.menu.action_menu, menu);
37
		return true;
38
	}
39
40
	private View getContentView() {
41
		LinearLayout linearLayout = new LinearLayout(this);
42
		linearLayout.setOrientation(LinearLayout.HORIZONTAL);
43
		linearLayout.setGravity(Gravity.CENTER);
44
		LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
45
				LinearLayout.LayoutParams.WRAP_CONTENT,
46
				LinearLayout.LayoutParams.WRAP_CONTENT);
47
		layoutParams.gravity = Gravity.CENTER_VERTICAL;
48
49
		Button button1 = new Button(linearLayout.getContext());
50
		button1.setText("Button1");
51
		button1.setLayoutParams(layoutParams);
52
		linearLayout.addView(button1);
53
54
		Button button2 = new Button(linearLayout.getContext());
55
		button2.setText("Button2");
56
		button2.setLayoutParams(layoutParams);
57
		linearLayout.addView(button2);
58
		return linearLayout;
59
	}
60-
}
60+
}
61
62
63
and this my menu xml...
64
65
<?xml version="1.0" encoding="utf-8"?>
66
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
67
68
    <item
69
        android:id="@+id/item1"
70
        android:showAsAction="always"
71
        android:title="Item1"
72
        android:visible="true"/>
73
    <item
74
        android:id="@+id/item2"
75
        android:showAsAction="always"
76
        android:title="Item2"
77
        android:visible="true"/>
78
79
</menu>