Android - specifying a custom theme for a custom dialog. AlertDialog.Builder wraps content in a dialog box

I created a custom theme that inherits from "Theme.Holo.Light.Dialog".

<?xml version="1.0" encoding="utf-8"?> <resources> <style name="cust_dialog" parent="@android:style/Theme.Holo.Light.Dialog"> </style> </resources> 

My code is:

 private AlertDialog testDialog; AlertDialog.Builder testBuilder; LayoutInflater inflater = (LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.test_dialog, (ViewGroup) findViewById(R.id.test_root)); testBuilder = new AlertDialog.Builder(this, R.style.cust_dialog); testBuilder.setView(layout); testBuilder.setTitle("Support"); testDialog = testBuilder.create(); testDialog.show(); 

This causes my dialog to be in the dialog box. How to fix it?

Thanks.

EDIT ::

This is my test_dialog.xml layout:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/test_root" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:id="@+id/test1" android:layout_width="300dp" android:layout_height="75dp" android:text="@string/test" android:gravity="center" /> <Button android:id="@+id/test2" android:layout_width="300dp" android:layout_height="75dp" android:text="@string/test" android:layout_below="@id/test1" android:gravity="center" /> </RelativeLayout> 
+4
source share
3 answers

try it.

 ContextThemeWrapper ctw = new ContextThemeWrapper( this, R.style.MyTheme ); AlertDialog.Builder builder= new AlertDialog.Builder( ctw ); LayoutInflater inflater = (LayoutInflater) ctw.getSystemService(LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.customdialogue, (ViewGroup) findViewById(R.id.layout_root)); 
+5
source

It is very important to get the inflater for the layout not through the usuall context, but through the context wrapper context ... struggling a bit at this point

0
source

You can try this

 AlertDialog.Builder builder = new AlertDialog.Builder(activity, R.layout.test_dialog); 
0
source

Source: https://habr.com/ru/post/1396870/


All Articles