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>