自定义弹窗

 一、仅更改弹窗的显示内容android

View view = View.inflate(this, R.layout.**, null);ide

new AlertDialog.Builder(this).setView(view);ui

二、更改弹窗的背景this

若是使用AlertDialog的setView,弹窗的周边会有黑边出现,这时候则须要这么作spa

  
  
  
  
  1. Dialog dialog = new Dialog(this, R.style.dialog_style); 
  2. View view = View.inflate(this, R.layout.**, null); 
  3. dialog.setContentView(view); 
  4. dialog.show(); 
  5. dialog.getWindow().setLayout(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); //自适应大小

dialog_style:xml

  
  
  
  
  1. <style name = "dialog_style" parent="@android:style/Theme.Dialog"> 
  2.      <item name = "android:windowBackground">@drawable/dialog_bg</item> 
  3.       <item name = "android:windowNoTitle">true</item> 
  4. </style> 

dialog_bg:utf-8

  
  
  
  
  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android" > 
  3.     <solid android:color="#00000000"/> 
  4. </shape> 

dialog_bg 用于去掉黑色边,View中设置好须要的背景.get

三、若是使用AlertDialogit

AlertDialog dialog = AlertDialog.Builder(this).create();io

dialog.show();

Window = dialog.getWindow();

view.setContentView(R.layout.**);

使用这种方法能够达到背景更换的效果,可是若是添加了EditText会出现,EditText不能弹出输入法的问题?

相关文章
相关标签/搜索