我正在尝试使我的AlertDialog透明,因为我在alertdialog下有一个backgroundimage,我尝试了与此情况相关的stackoverflow的所有方法,但无论我尝试了什么我都不能..也许我错过了一些简单的东西所以我需要帮助。
这是我的代码
LayoutInflater li = LayoutInflater.from(LoginActivity.this);
View promptsView = li.inflate(R.layout.activity_login, null);
final AlertDialog alertDialogBuilder = new AlertDialog.Builder(LoginActivity.this)
.setView(promptsView)
.setCancelable(false)
.setPositiveButton(android.R.string.ok, null) //Set to null. We override the onclick
.setNegativeButton(android.R.string.cancel, null)
.create();
Window window = alertDialogBuilder.getWindow();
window.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
alertDialogBuilder.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
// positive button and negative button controls.
}
});
alertDialogBuilder.show();
这是我的xml(activity_login - promptsView)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="10dp" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login`enter code here`"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FE9A2E" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/kadi"
android:layout_alignBottom="@+id/kadi"
android:layout_alignLeft="@+id/textView1"
android:text="K.Adı :"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/pass"
android:layout_alignBottom="@+id/pass"
android:layout_alignLeft="@+id/textView2"
android:text="Şifre : "
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/pass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/kadi"
android:layout_alignRight="@+id/kadi"
android:layout_below="@+id/kadi"
android:layout_marginTop="14dp"
android:ems="10"
android:inputType="textPassword" />
<EditText
android:id="@+id/kadi"
android:layout_width="234dp"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_marginLeft="14dp"
android:layout_marginTop="14dp"
android:layout_toRightOf="@+id/TextView01"
android:ems="10" />
</RelativeLayout>
希望你能帮助我。