我正在显示具有自定义布局的对话框。它适用于除小米设备以外的所有android设备。在小米设备中,它显示带有黑色背景的对话框。
例如: Custom Dialog with black background
这是我的代码:
public void showPopUp(){
myDialog.setContentView(R.layout.pop_up_impact);
myDialog.setCanceledOnTouchOutside(false);
WindowManager.LayoutParams lp = myDialog.getWindow().getAttributes();
lp.dimAmount=0.0f;
myDialog.getWindow().setAttributes(lp);
myDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
myDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
Typeface gibsonbold = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/gibsonbold.ttf");
Typeface gibsonregular = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/gibsonregular.ttf");
Typeface opensansregular = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/opensansregular.ttf");
Typeface opensansbold = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/opensansbold.ttf");
popUpText = (TextView) myDialog.findViewById(R.id.pop_up_text);
popUpId = (TextView) myDialog.findViewById(R.id.id_pop_up);
close = (ImageView) myDialog.findViewById(R.id.close_pop_up);
background = (RelativeLayout) myDialog.findViewById(R.id.background);
popUpText.setTypeface(opensansregular);
loadContent();
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Blurry.delete((ViewGroup) mainLayout);
spm.SetPopUpFirstTimeLauch(false);
startActivity(getIntent());
myDialog.dismiss();
}
});
myDialog.show();
}
这是pop_up_impact.xml布局代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="@dimen/_260sdp"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:clickable="true"
android:gravity="center"
android:layout_gravity="center"
android:orientation="vertical"
android:background="@android:color/transparent"
android:layout_marginLeft="@dimen/_25sdp"
android:layout_marginTop="@dimen/_18sdp"
android:layout_marginRight="@dimen/_25sdp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/id_pop_up"
android:visibility="gone"/>
<RelativeLayout
android:id="@+id/background"
android:background="@android:color/transparent"
android:layout_width="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_marginTop="@dimen/_7sdp"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/_40sdp"
android:layout_centerHorizontal="true"
android:layout_marginLeft="@dimen/_27sdp"
android:layout_marginRight="@dimen/_27sdp"
android:alpha="0.5"
android:background="#fff"
android:gravity="center|bottom"/>
<TextView
android:id="@+id/pop_up_text"
android:layout_width="match_parent"
android:layout_marginTop="@dimen/_9sdp"
android:layout_marginRight="@dimen/_30sdp"
android:layout_marginLeft="@dimen/_30sdp"
android:layout_height="wrap_content"
android:textAlignment="center"
android:layout_centerHorizontal="true"
android:textSize="@dimen/_7ssp"
android:fontFamily="@font/opensansregular"
android:text=" "/>
</RelativeLayout>
<ImageView
android:id="@+id/close_pop_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:src="@drawable/closebox"
android:layout_alignParentEnd="true"
/>
有人知道如何解决此问题吗?还是正常?
答案 0 :(得分:0)
像这样设置对话框
Dialog dialog = Dialog(context)
dialog.getWindow().setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT));
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(false);
dialog.setContentView(R.layout.pop_up_impact);