效果图:
核心代码:
1自定义Dialog类
/**
* Created by Administrator on 2016/6/16.
*/
public class MyDialog extends Dialog {
public MyDialog(Context context, View layout) {
super(context);
setContentView(layout);
getWindow().setBackgroundDrawable(new BitmapDrawable());
// 其实这条蓝色的线条叫做titleDiver,去掉方法如下
try {
int dividerID = context.getResources().getIdentifier("android:id/titleDivider", null, null);
View divider = findViewById(dividerID);
divider.setBackgroundColor(Color.TRANSPARENT);
} catch (Exception e) {
//上面的代码,是用来去除Holo主题的蓝色线条
e.printStackTrace();
}
}
}
2调用MyDialog
// 选择是否更新
private void methodSelectUpdate() {
View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.dialog_version_update, null);
final MyDialog dialogDeleteOrder = new MyDialog(MainActivity.this, view);
dialogDeleteOrder.setCanceledOnTouchOutside(false);
dialogDeleteOrder.setCancelable(false);
dialogDeleteOrder.show();
TextView tvContent= (TextView) view.findViewById(R.id.tvContent);
// tvContent.setText(content);
// 取消
TextView tvCancel = (TextView) view.findViewById(R.id.tvCancel);
tvCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (dialogDeleteOrder.isShowing()) {
dialogDeleteOrder.dismiss();
}
}
});
// 确定
TextView tvServiceCall = (TextView) view.findViewById(R.id.tvServiceCall);
tvServiceCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (dialogDeleteOrder.isShowing()) {
dialogDeleteOrder.dismiss();
}
}
});
}
3MyDialog的布局文件dialog_version_update.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<LinearLayout
android:layout_width="260dp"
android:layout_height="wrap_content"
android:background="@drawable/buttonstyle_sercice_call"
android:orientation="vertical">
<LinearLayout
android:layout_margin="2dp"
android:layout_width="match_parent"
android:layout_height="85dp"
android:background="#FFFFFF"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="发现新版本"
android:textSize="18sp"
android:textColor="#000000"
/>
<TextView
android:id="@+id/tvContent"
android:textSize="18sp"
android:textColor="#000000"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#E1E1E1"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="42dp"
android:background="#FFFFFF"
android:orientation="horizontal">
<TextView
android:id="@+id/tvCancel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="1"
android:background="@drawable/recycler_bg_but"
android:text="取消"
android:gravity="center"
/>
<ImageView
android:layout_width="0.5dp"
android:layout_height="match_parent"
android:background="#E1E1E1"
/>
<TextView
android:id="@+id/tvServiceCall"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="1"
android:background="@drawable/recycler_bg_but"
android:text="更新"
android:gravity="center"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
源码下载:MyApplication02----app
http://download.csdn.net/detail/zhaihaohao1/9700744