編輯:關於android開發
Android中的設置按鈕:長按或點擊菜單鍵
1.長按選項:
布局文件:
1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical" 6 android:paddingBottom="@dimen/activity_vertical_margin" 7 android:paddingLeft="@dimen/activity_horizontal_margin" 8 android:paddingRight="@dimen/activity_horizontal_margin" 9 android:paddingTop="@dimen/activity_vertical_margin" 10 tools:context=".MenuActivity" > 11 12 <TextView 13 android:id="@+id/menutext1" 14 android:layout_width="fill_parent" 15 android:layout_height="wrap_content" 16 android:text="第一種方法創建菜單" 17 android:textSize="20sp" /> 18 19 <TextView 20 android:id="@+id/menutext2" 21 android:layout_width="fill_parent" 22 android:layout_height="wrap_content" 23 android:text="第二種方法創建菜單" 24 android:textSize="20sp" /> 25 26 <ListView 27 android:id="@+id/menulist" 28 android:layout_width="fill_parent" 29 android:layout_height="fill_parent" 30 android:layout_marginTop="50dp" > 31 </ListView> 32 33 </LinearLayout>
實現過程:
1 private ListView list;
2 private TextView lv;
3
4 String[] str = { "TextView", "EditView", "Toast(消息框)" };
5
6 @Override
7 protected void onCreate(Bundle savedInstanceState) {
8 super.onCreate(savedInstanceState);
9 setContentView(R.layout.activity_menu);
10
11 list = (ListView) findViewById(R.id.menulist);
12 ArrayAdapter<String> arr = new ArrayAdapter<String>(this,
13 android.R.layout.simple_list_item_1, str);
14 list.setAdapter(arr);
15
16 list.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
17
18 @Override
19 public void onCreateContextMenu(ContextMenu menu, View v,
20 ContextMenuInfo menuInfo) {
21 menu.clear();
22 menu.clearHeader();
23 menu.setHeaderIcon((R.drawable.ic_launcher));
24 menu.setHeaderTitle("我是ListView");
25 menu.add(3, 6, 0, "刪除");
26 menu.add(3, 7, 1, "修改");
27 }
28 });
29 // 第一種方法
30 TextView tv = (TextView) findViewById(R.id.menutext1);
31 this.registerForContextMenu(tv);
32 // 第二種方法
33 lv = (TextView) findViewById(R.id.menutext2);
34 lv.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
35
36 @Override
37 public void onCreateContextMenu(ContextMenu menu, View v,
38 ContextMenuInfo menuInfo) {
39 menu.setHeaderTitle("長度-ContextMenu");
40 menu.add(0, 1, 0, "復制");
41 SubMenu sb = menu.addSubMenu("查找");
42 sb.add(1, 2, 0, "按id查找");
43 sb.add(1, 3, 0, "按名稱查找");
44 }
45 });
46 }
2.長按菜單項:
1 private ListView list;
2 private TextView lv;
3
4 String[] str = { "TextView", "EditView", "Toast(消息框)" };
5
6 @Override
7 protected void onCreate(Bundle savedInstanceState) {
8 super.onCreate(savedInstanceState);
9 setContentView(R.layout.activity_menu);
10
11 list = (ListView) findViewById(R.id.menulist);
12 ArrayAdapter<String> arr = new ArrayAdapter<String>(this,
13 android.R.layout.simple_list_item_1, str);
14 list.setAdapter(arr);
15
16 list.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
17
18 @Override
19 public void onCreateContextMenu(ContextMenu menu, View v,
20 ContextMenuInfo menuInfo) {
21 menu.clear();
22 menu.clearHeader();
23 menu.setHeaderIcon((R.drawable.ic_launcher));
24 menu.setHeaderTitle("我是ListView");
25 menu.add(3, 6, 0, "刪除");
26 menu.add(3, 7, 1, "修改");
27 }
28 });
29 // 第一種方法
30 TextView tv = (TextView) findViewById(R.id.menutext1);
31 this.registerForContextMenu(tv);
32 // 第二種方法
33 lv = (TextView) findViewById(R.id.menutext2);
34 lv.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
35
36 @Override
37 public void onCreateContextMenu(ContextMenu menu, View v,
38 ContextMenuInfo menuInfo) {
39 menu.setHeaderTitle("長度-ContextMenu");
40 menu.add(0, 1, 0, "復制");
41 SubMenu sb = menu.addSubMenu("查找");
42 sb.add(1, 2, 0, "按id查找");
43 sb.add(1, 3, 0, "按名稱查找");
44 }
45 });
46 }
Over
標簽: Android, menu
android AsynTask處理返回數據和AsynTask使用get,post請求,androidasyntask
android AsynTask處理返回數據和AsynTask使用get,post請求,androidasyntaskAndroid是一個單線程模型,Android界面(
使用AndroidStudio上傳忽略文件至SVN Server的解決措施,androidstudiosvn
使用AndroidStudio上傳忽略文件至SVN Server的解決措施,androidstudiosvn 在同組項目進行共享時,容易把本地的配置文件比如*.iml等
android ndk開發(二)實現一個官方demo,androidndk
android ndk開發(二)實現一個官方demo,androidndk實現了一個官方的demo:bitmap-plasma(水波紋) 源代碼就在samples文件夾下
使用HttpURLConnection實現在android客戶端和服務器之間傳遞對象
使用HttpURLConnection實現在android客戶端和服務器之間傳遞對象 一般情況下,客戶端和服務端的數據交互都是使用json和XML,相比於XML,json