Android中自定义Dialog常用的两种方式

第一种:
  
my_dialog.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="wrap_content"android:orientation="vertical" ><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:gravity="center"android:orientation="horizontal"android:padding="2dip" ><EditTextandroid:id="@+id/edittext1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:typeface="monospace"android:width="180dip" /></LinearLayout></LinearLayout>
  
LayoutInflater inflater = LayoutInflater.from(EA6Activity.this);final View DialogView = inflater.inflate(R.layout.dialog, null);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);builder.setView(DialogView);
.
.
.
builder.create();
  
第二种:
public class MyDialog extends Dialog{
   public MyDialog(Context context) {   super(context);   // TODO Auto-generated constructor stub 
  }
  @Override protected void onCreate(Bundle savedInstanceState) {  // TODO Auto-generated method stub  super.onCreate(savedInstanceState);
  //全屏  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,    WindowManager.LayoutParams.FLAG_FULLSCREEN);
//无标题  requestWindowFeature(Window.FEATURE_NO_TITLE);   setContentView(R.layout.my_dialog);
 }
}
实现的时候new就可以了,当然,有的说Activity可以把启动模式调为Dialog也可以实现,是的,可以实现,但毕竟还是Activity。


更多相关文章

  1. Android创建和删除桌面快捷方式
  2. Android中创建和检测快捷方式
  3. Android UI设计模式
  4. Android常用屏幕适配方式
  5. 【原创】Android 4.4前后版本读取图库图片方式的变化

随机推荐

  1. 制定2个月学习Android的计划
  2. 解决ListView 下拉时出现黑色阴影
  3. Android内存使用——垃圾回收LOG,GC_CONCU
  4. Android(安卓)Jetpack Components of Roo
  5. android连接数据库sqllist基础操作学习:
  6. 在Android Studio中,如何在app中打开链接
  7. android listview单击事件
  8. android 关闭外音
  9. Android 之使用LocalBroadcastManager解
  10. Android检测系统中是否存在某进程