Android自定义对话框列表
16lz
2021-12-04
学习Android,在文件操作时弹出一个对话框作为弹出菜单(习惯叫法 :-) ):
new AlertDialog.Builder(MyActivity.this) .setTitle("标题") .setItems(menu,listener) .show();其中:
menu:
String[] menu={"打开","重命名","删除","复制","剪切","自动重命名"};
listener:
OnClickListener listener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) {//TODO 点击项处理
}};
当menu内容多时,一屏显示不下,看了看间隔比较到,字体也比较大,如果修改得小一些就可以在一屏显示了。
改造对话框:
List<Map<String,String>> filemenu= new ArrayList<Map<String, String>>(); for(int i=0;i<menu.length;i++){ Map<String,String> m=new HashMap<String,String>(); m.put("id",menu[i]); filemenu.add(m); } SimpleAdapter adapter = new SimpleAdapter(FileManager.this, (List<Map<String,String>>) filemenu, R.layout.popupmenu, new String[] { "id"}, new int[] {R.id.txtItem}); new AlertDialog.Builder(FileManager.this) .setTitle(R.string.OptionMenuTitle) //通过自定义适配器来显示菜单 .setAdapter(adapter,listener).show();
其中R.layout.popupmenu:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="TextView" android:id="@+id/txtItem" android:textColor="@color/blue" android:textSize="24sp" > </TextView> <ListView android:id="@id/android:list" android:drawSelectorOnTop="false" android:layout_width="wrap_content" android:layout_height="wrap_content"></ListView> </LinearLayout>只需要修改这个xml布局文件就可以修改弹出项的外观了。
更多相关文章
- Android(安卓)Studio 配置
- Android(安卓)PopupWindow的使用
- 【高通平台】安卓平板,使用QQ 视频通话,视频旋转90度问题修改
- [RK3399] [Android(安卓)9.0] 调试2560x1440分辨率EDP显示屏,和碰
- 修改 ActivityManagerService.java 去掉 android 系统报错和程序
- 修改 android版本 签名问题
- Android全屏显示 无标题栏、全屏、设置为横屏
- [Android]设置Activity为全屏显示的两种方法
- 修改android版本号