Android 自定义AlertDialog 去黑边终极解决方案(亲测有效!)
来源:互联网 发布:淘宝默认付款是几天 编辑:程序博客网 时间:2024/05/21 09:02
问题:自定义AlertDialog出现黑边
解决问题:
运行代码段:
View view = View.inflate(context, R.layout.dialog_common, null);mDialog = new AlertDialog.Builder(context).create();mDialog.setView(view);mDialog.show();
dialog_common.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@drawable/shape_dialog_white"android:orientation="vertical" ><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginBottom="35dp"android:layout_marginTop="35dp"android:gravity="center" ><TextViewandroid:id="@+id/dialog_tv_content"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/dialog_edit_wall_title"android:textColor="@android:color/black"android:textSize="19sp" /></LinearLayout><Viewandroid:layout_width="match_parent"android:layout_height="1dp"android:background="@color/app_color" /><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center" ><TextViewandroid:id="@+id/dialog_tv_left"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginBottom="12dp"android:layout_marginTop="12dp"android:layout_weight="1"android:gravity="center"android:text="@string/dialog_edit_wall_secede"android:textColor="@android:color/black" /><TextViewandroid:id="@+id/dialog_tv_right"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginBottom="12dp"android:layout_marginTop="12dp"android:layout_weight="1"android:gravity="center"android:text="@string/dialog_new_reply_cancel"android:textColor="@color/app_color" /></LinearLayout></LinearLayout>
运行时截图(出现一圈的黑边!):
解决问题:
1. 百度搜索“Android 自定义AlertDialog去除黑边”,得出总结3个字:“然并卵”!大部分都是这样做:
修改代码:
mDialog.setView(view);
为:
mDialog.setView(view,0,0,0,0);
运行时截图(什么叫“然并卵”,粗的黑边变成细的黑边,结果黑边还在):
2. 分析:自己写的layout没什么问题,显然是AlertDialog的style或者是theme的问题。
3. 终极解决方案:
增加一个style
<!-- styles.xml on API 14+ devices --><style name="SampleTheme.Light" parent="android:Theme.Holo.Light.DarkActionBar"><item name="android:windowNoTitle">true</item></style>
添加到layout中或者AndroidManifest.xml(我是添加到AndroidManifest.xml中,layout可以自己去加看看)
<activity android:name="com.kesar.ui.MainActivity"android:theme="@style/SampleTheme.Light"/>
运行时截图(接下来就是见证奇迹的时刻!):
附件列表
- 1.png
- 2.png
- 3.png
2 0
- Android 自定义AlertDialog 去黑边终极解决方案(亲测有效!)
- [原创] Android 自定义AlertDialog 去黑边终极解决方案(亲测有效!)
- Android 自定义视频录制终极解决方案(翻转问题)
- 如何去掉自定义AlertDialog进行圆角化的时候,出现的阴影或者黑色边角(亲测有效)
- android自定义对话框(AlertDialog)
- Android App 沉浸式状态栏解决方案(亲测有效)
- android自定义AlertDialog对话框中的EditText无法弹出输入法解决方案
- Androidの自定义对话框AlertDialog(一)
- Androidの自定义对话框AlertDialog(二)
- android 之自定义 AlertDialog
- android Alertdialog 自定义
- android AlertDialog自定义大小
- Android自定义AlertDialog组件
- android AlertDialog自定义布局
- 【Android】自定义AlertDialog布局
- Android 自定义AlertDialog
- 【Android开发】自定义AlertDialog
- android自定义AlertDialog
- 如何为我们的Snappy Ubuntu应用编译并打包Snap(1)
- Android Edittext输入后切换界面出现白块
- A+B for Input-Output Practice (V)
- iOS App瘦身注意armv7 armv7s arm64
- C调用dll示例代码
- Android 自定义AlertDialog 去黑边终极解决方案(亲测有效!)
- 四、ObjectARX 修改对象的属性
- 关于java中double类型的比较大小的问题
- Swift学习 OC字符串和Swift字符串的转换
- Android ContentProvider深入分析
- android的事件传递
- A+B for Input-Output Practice (VI)
- linux下安装oracle_11g
- ava中的Iterator和Iterable