Как ни странно, это работало нормально, вот как это выглядит в моем приложении, выпущенном в Google Play:
А вот как это выглядит сейчас:
Все, что я сделал, это перешел на AndroidX.
Вот мой макет диалога:
<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:id = "@+id/dialogLinear"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:orientation = "vertical"
android:padding = "10dp">
<FrameLayout
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_marginBottom = "10dp"
android:background = "@drawable/rounded_corners">
<Button
android:id = "@+id/btnAdd2"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:background = "?android:attr/selectableItemBackground"
android:text = "@string/import_video"
android:textColor = "@color/dark_text" />
</FrameLayout>
<FrameLayout
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:background = "@drawable/rounded_corners">
<Button
android:id = "@+id/btnAdd1"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:background = "?android:attr/selectableItemBackground"
android:text = "@string/add_student"
android:textColor = "@color/dark_text" />
</FrameLayout>
</LinearLayout>
и вот как я его надуваю:
View dialogView = View.inflate(getApplicationContext(), R.layout.dialog_main, null);
LinearLayout dialogLinear = dialogView.findViewById(R.id.dialogLinear);
//Here is where is set the background to transparent
dialogLinear.setBackgroundColor(0x00000000);
final AlertDialog alertD = new AlertDialog.Builder(this).create();
Button btnAdd1 = dialogView.findViewById(R.id.btnAdd1);
Button btnAdd2 = dialogView.findViewById(R.id.btnAdd2);
btnAdd1.setTypeface(mCustom_font_Bold);
btnAdd2.setTypeface(mCustom_font_Bold);
btnAdd1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Do stuff
}
});
btnAdd2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Do stuff
}
});
alertD.setView(dialogView);
if (alertD.getWindow() != null) {
alertD.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
}
alertD.show();
Я искал и не мог найти, почему это происходит. Может кто-нибудь, пожалуйста, дайте мне совет?
Я попытался установить его в самом макете.
Редактировать 1:
Попробовав ответ ниже, теперь он выглядит так, а не выше:
я решил это, добавив следующие стили:
<style name = "NewDialog">
<item name = "android:windowIsFloating">true</item>
<item name = "android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name = "android:backgroundDimEnabled">true</item>
<item name = "android:background">@android:color/transparent</item>
</style>
Настройка стиля так:
final AlertDialog alertD = new AlertDialog.Builder(this, R.style.NewDialog).create();
И чтобы исправить то, что произошло в Edit 1, я изменил свой LinearLayout на RelativeLayout
@NileshRathod У меня уже есть alertD.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));, и я попробовал alertD.getWindow().setBackgroundDrawableResource(android.R.color.transparent); с тем же результатом.
Вы пробовали применить background прозрачность к dialogLinear?




Определите тему в своем styles.xml
<style name = "CustomDialog" parent = "android:Theme.Dialog">
<item name = "android:windowIsTranslucent">true</item>
<item name = "android:windowBackground">@android:color/transparent</item>
</style>
И назначьте эту тему своему AlertDialog
final AlertDialog alertD = new AlertDialog.Builder(this,R.style.CustomDialog).create();
Или
2. Вам следует попробовать использовать Dialog вместо AlertDialog. Как пояснено в этом Отвечать.