AlertDialog内容自定义

 

LayoutInflater factory = LayoutInflater.from(this);
        final View dialogView = factory.inflate(R.layout.share, null);

        final AlertDialog dlg = new AlertDialog.Builder(this)
        .setTitle("rrrr")
        .setView(dialogView).create();
        dlg.show();
        dlg.getWindow().setLayout(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

 

 

//方法二
    	final AlertDialog dlg = new AlertDialog.Builder(this).create();
    	dlg.show();
    	Window window = dlg.getWindow();    	 
    	// *** 主要就是在这里实现这种效果的.    	 
    	// 设置窗口的内容页面
    	window.setContentView(R.layout.dialog);
    	Button bt_cancel = (Button)window.findViewById(R.id.d_cancel);
    	Button bt_sure = (Button)window.findViewById(R.id.d_sure);
    	bt_cancel.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				dlg.dismiss();
			}    		
    	});
    	bt_sure.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				dlg.dismiss();
				stopService(new Intent(BaseActivity.this, DrawService.class));
		
				if (activityList.size() > 0) { 
					for (Activity activity : activityList) { 
						activity.finish(); 
					} 
				//	android.os.Process.killProcess(android.os.Process.myPid()); 
				} 

			}    		
    	});

dialog.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:background="@drawable/corner_round_dialog" >
   
    <LinearLayout
        android:id="@+id/d_first"
        android:layout_marginTop="5dp"          
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"          
        android:layout_centerHorizontal="true">
         <ImageView
            android:layout_width="wrap_content" 
         	android:layout_height="wrap_content"  
         	android:src="@drawable/dialog_icon"
         	android:scaleType="center"/>
         <TextView
            style="@style/dialog_title"
	        android:layout_width="wrap_content"
	        android:layout_height="wrap_content" 	        
			android:text="退出"/>         
     </LinearLayout>
    
    <TextView
        style="@style/dialog_content"
        android:layout_below="@id/d_first"
        android:padding="5dp"       
        android:id="@+id/d_second"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_marginLeft="20dp"
		android:text="您确定要退出应用吗?"/>
    
 
	    <View 
	        android:layout_marginTop="5dip" 
	        android:id="@+id/d_third"
	        android:layout_below="@id/d_second"       
	        android:layout_centerHorizontal="true" 
	        android:background="@android:color/black"
	        android:layout_width="230dp"
	        android:layout_height="1dp" />
    
    <LinearLayout 
        android:padding="5dp"        
        android:layout_centerHorizontal="true"
        android:layout_below="@id/d_third"
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:orientation="horizontal">
         <Button
             style="@style/dialog_button"
             android:id="@+id/d_cancel"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"            
             android:background="@drawable/button_dialog"
             android:text="取消"/>
            <!-- 取消 -->
                 
         <Button
             style="@style/dialog_button"
             android:id="@+id/d_sure"
             android:layout_marginLeft="10dip"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"             
             android:background="@drawable/button_dialog"
             android:text="确定"/> <!-- 确定 -->
   </LinearLayout> 
   
</RelativeLayout>


 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值