自定义AlertDialog.Builder

来源:互联网 发布:mac dare you和diva 编辑:程序博客网 时间:2024/06/14 10:08
AlertDialog.Builder builder = new Builder(MainActivity.this);
                zdy = builder.create();
                View view1 = View.inflate(getApplicationContext(),  R.layout.jikao, null);
                zdy.setView(view1);
                bar = (ProgressBar) view1.findViewById(R.id.jdt);
                textView = (TextView) view1.findViewById(R.id.sz);
                zdy.show();
//消失
zdy.dismiss();
//AlertDialog视图
<ProgressBar
        android:id="@+id/jdt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:focusable="true"
        style="@android:style/Widget.ProgressBar.Horizontal"
        android:progress="0"
        />
      <TextView
        android:id="@+id/sz"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="0%"
        android:textSize="20sp"


//定义AlertDialog的宽高
  1. AlertDialog dialog = builder.create();  
  2. dialog.setView(view);  
  3. dialog.show();  
  4. WindowManager m = getWindowManager();    
  5. Display d = m.getDefaultDisplay();  //为获取屏幕宽、高    
  6. android.view.WindowManager.LayoutParams p = dialog.getWindow().getAttributes();  //获取对话框当前的参数值    
  7. p.height = (int) (d.getHeight() * 0.3);   //高度设置为屏幕的0.3  
  8. p.width = (int) (d.getWidth() * 0.5);    //宽度设置为屏幕的0.5   
  9. dialog.getWindow().setAttributes(p);     //设置生效 


0 0