AlertDialog去除黑边自定义布局
来源:互联网 发布:php artisan key 编辑:程序博客网 时间:2024/05/01 18:30
自定义布局文件
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_height="fill_parent" android:layout_width="fill_parent"><RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content"android:background="@drawable/popup_title" android:id="@+id/about_us_rel01"><TextView android:id="@+id/about_us_title" android:layout_width="wrap_content"android:layout_height="wrap_content" android:text="关于我们" android:layout_marginLeft="20dip" android:textSize="20dip"/></RelativeLayout><RelativeLayout android:layout_height="wrap_content" android:layout_below="@+id/about_us_rel01"android:background="@drawable/popup_bg" android:id="@+id/about_us_rel02"android:layout_width="fill_parent" android:gravity="center" ><ListView android:id="@+id/test_alertdialog_listview"android:layout_height="wrap_content" android:layout_width="wrap_content"></ListView></RelativeLayout></RelativeLayout>
java代码final String[] datas ={"data1","data2"};LayoutInflater inflater = this.getLayoutInflater();View view = inflater.inflate(R.layout.test_alertdialog_listview,null);ListView lv = (ListView)view.findViewById(R.id.test_alertdialog_listview);lv.setAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1,datas));lv.setOnItemClickListener(new OnItemClickListener(){@Overridepublic void onItemClick(AdapterView<?> parent, View view,int position, long id) {alertdialog.dismiss();Toast.makeText(TestAndroid.this, datas[position], Toast.LENGTH_LONG).show();}});alertdialog = new AlertDialog.Builder(this)//.setView(view);.setItems(datas, new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stub}}).create();// 在此使用setview方法可以设置布局文件和alertdialog四周边框的距离,可以消除黑边框alertdialog.setView(view, 0, 0, 0, 0);alertdialog.show();
此外,我们还可以通过设置dialog的样式来定义,消除边框
使用样式文件,在values 目录下新建styles.xml文件,编写如下代码:
<resources><style name="dialog" parent="@android:style/Theme.Dialog"><item name="android:windowFrame">@null</item><item name="android:windowIsFloating">true</item><item name="android:windowIsTranslucent">false</item><item name="android:windowNoTitle">true</item><item name="android:background">@android:color/black</item><item name="android:windowBackground">@null</item><item name="android:backgroundDimEnabled">false</item></style></resources>
调用时,使用AlerDialog的接口类,Dialog 接口编写如下代码:
Dialog dialog =new Dialog(SetActivity.this, R.style.dialog); dialog.setContentView(R.layout.test); dialog.show();
下面我们查看一下Dialog的源码文件,里面的构造函数为如下:
public Dialog(Context context, int theme) { mContext =new ContextThemeWrapper(context, theme ==0? com.android.internal.R.style.Theme_Dialog : theme); mWindowManager = (WindowManager)context.getSystemService("window"); Window w = PolicyManager.makeNewWindow(mContext); mWindow = w; w.setCallback(this); w.setWindowManager(mWindowManager, null, null); w.setGravity(Gravity.CENTER); mUiThread = Thread.currentThread(); mDismissCancelHandler =new DismissCancelHandler(this); }
这里面我们可以看出,Android 使用了默认的构造函数为Dialog 设置样式,如果没有为其设置样式,即默认加载事先编写好的样式文件,Dialog 一共由多个9.png的图片构成,大部分都是带有边框的9.png图片,所以就是为什么我们上边的样式文件要将其背景去除掉。这个东西搞了我好久,希望对你有帮助
来自:http://www.eoeandroid.com/forum-viewthread-tid-32577-highlight-%2Bdialog.html
http://www.eoeandroid.com/thread-28762-1-1.html
- AlertDialog去除黑边自定义布局
- 去除自定义AlertDialog黑边
- 去除自定义alertdialog(dialog)黑边
- 笔记107--去除自定义AlertDialog黑边
- Android2.3 自定义AlertDialog布局 去上下黑边
- android AlertDialog去除黑边白边自定义布局
- Android中自定义AlertDialog,去除黑,白边框
- android 自定义Dialog去除黑边
- 自定义dialog并且去除黑边
- Android自定义AlertDialog去掉黑边的方法
- android AlertDialog自定义布局
- 【Android】自定义AlertDialog布局
- 自定义AlertDialog布局
- 自定义AlertDialog对话框布局
- AlertDialog自定义布局
- 自定义AlertDialog布局
- Android AlertDialog自定义布局
- AlertDialog自定义布局
- mock 例子
- java中MD5加密方法实例
- 滑动窗口协议-百度百科
- umask的知识
- 数据数连接过大的问题
- AlertDialog去除黑边自定义布局
- java正则表达式获取指定HTML标签的指定属性值
- git版本控制:如何处理当前分支为*(no branch)的情况
- Linux内核解读入门
- java中的日期在数据库和页面之间的相互转换
- 后缀数组模版
- 您的身上是否具备了成功的“基因”?
- 连连看游戏~~~可以直接用鼠标点击两个格子来消去。。。
- 一个Spring + Json异常的问题