今天遇到一个大难题哦,不过有大牛一眼就瞄出来了,然后就解决了,AlertDialog和Dialog自定义后圆角的处理,如果你跟我一样没有看到这些细节的话就栽了,用AlertDialog不能使得圆角背景透明化,所以要用Dialog处理才行,也就是下面的方法。

    Dialog:

private static Dialog mDialog;// 加载gridview中的item的xml方法public static View getView(Context context, int layoutId) {LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);View layout = inflater.inflate(layoutId, null);return layout;}/** * 显示自定义对话框 *  * @param context * @param message * @param listener */public static void showDialog(final Context context, String message,final IAlertDialogButtonListener listener) {View dialogView = null;// Dialog.Builder builder = new Builder(context,// R.style.Theme_Transparent);mDialog = new Dialog(context, R.style.Theme_Transparent);dialogView = getView(context, R.layout.dialog_view);Button btn_ok = (Button) dialogView.findViewById(R.id.btn_ok);Button btn_cancel = (Button) dialogView.findViewById(R.id.btn_cancel);TextView txt_dailog_message = (TextView) dialogView.findViewById(R.id.txt_dailog_message);txt_dailog_message.setText(message);btn_ok.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View arg0) {// 关闭dialogif (mDialog != null) {mDialog.cancel();}// 事件回调if (listener != null) {listener.onClick();}// 播放音效// MyPlayer.playTone(context, MyPlayer.INDEX_STONE_ENTER);}});btn_cancel.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View arg0) {// 关闭dialogif (mDialog != null) {mDialog.cancel();}// 播放音效// MyPlayer.playTone(context, MyPlayer.INDEX_STONE_CANCEL);}});// 为dialog设置View// builder.setView(dialogView);mDialog.setContentView(dialogView);// mDialog = builder.create();mDialog.show();}}

    AlertDialog:

/** * 显示自定义对话框 *  * @param context * @param message * @param listener */public static void showDialog(final Context context, String message,final IAlertDialogButtonListener listener) {View dialogView = null;AlertDialog.Builder builder = new Builder(context,R.style.Theme_Transparent);dialogView = getView(context, R.layout.dialog_view);ImageButton btn_ok = (ImageButton) dialogView.findViewById(R.id.btn_ok);ImageButton btn_cancel = (ImageButton) dialogView.findViewById(R.id.btn_cancel);TextView txt_dailog_message = (TextView) dialogView.findViewById(R.id.txt_dailog_message);txt_dailog_message.setText(message);btn_ok.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View arg0) {// 关闭dialogif (mAlertDialog != null) {mAlertDialog.cancel();}// 事件回调if (listener != null) {listener.onClick();}// 播放音效MyPlayer.playTone(context, MyPlayer.INDEX_STONE_ENTER);}});btn_cancel.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View arg0) {// 关闭dialogif (mAlertDialog != null) {mAlertDialog.cancel();}// 播放音效MyPlayer.playTone(context, MyPlayer.INDEX_STONE_CANCEL);}});// 为dialog设置Viewbuilder.setView(dialogView);mAlertDialog = builder.create();mAlertDialog.show();}

    af_dialog_background圆角:

<?xml version="1.0" encoding="utf-8"?>        

    dialog_view:

<?xml version="1.0" encoding="utf-8"?>                                                                    

    最后是style:

        @null        true        true        true        @android:color/transparent        @android:color/transparent        true        0.6    

    谢谢hongyang大神~~开心挣钱每一天

更多相关文章

  1. 采用回调Activity的形式创建AlertDialog单选列表框
  2. Android滑动菜单框架完全解析,教你如何一分钟实现滑动菜单特效
  3. Android对话框Dialog,PopupWindow,Toast的实现机制
  4. Android的Touch事件处理和手势
  5. Android实现TextView中部分文字监听事件
  6. android发送模拟按键消息,出现死锁,timeout的解决方法
  7. Android(安卓)事件分发源码分析
  8. [置顶] Android触摸事件分发
  9. 针对 CoordinatorLayout 及 Behavior 的一次细节较真

随机推荐

  1. Android封装jar包,把当前项目设置成module
  2. android studio线性布局,相对布局,TestView
  3. Android Bitmap和Canvas学习笔记
  4. [android] 隐式意图的配置
  5. Android(安卓)Drawable系列——Animation
  6. android sdk2.0分辨率的bug
  7. Android AsyncTask的优缺点详解
  8. 【android】应用架构一一一一一Activity
  9. Android基础教程——横竖切换监听、禁止
  10. AndroidUI自动化测试工具-UIautomator