如何使自定义警报对话框的宽度变大?
How to make an Custom Alert Dialog width larger?
实际上我的应用程序中有一个自定义的 AlertDialog,但我在其中实现了一个 SegmentButton 不适合 AlertDialog,如下面的屏幕所示。
显然,如果可能的话,我更愿意调整大小并使其适合 SegmentButton 中的元素,但如果不能的话,无论如何让整个 AlertDialog 变大都很棒
所以我想知道是否可以使该警告对话框的宽度更大。
这是我的 XML 自定义 AlertDialog
代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:gravity="center"
android:focusableInTouchMode="true"
android:background="#20d2d2d2"
android:orientation="vertical">
<TextView
android:id="@+id/deskART"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:text="VARIANTI"
android:textAlignment="center"
android:textColor="#008b58"
android:textSize="20sp"
android:textStyle="bold"
tools:ignore="HardcodedText" />
<SearchView
android:id="@+id/searchMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:iconifiedByDefault="false" />
<LinearLayout
android:id="@+id/TitleBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/desc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginEnd="2dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_weight="2"
android:text="Descrizione"
tools:ignore="HardcodedText" />
<TextView
android:paddingEnd="10dp"
android:id="@+id/preMeno"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:layout_weight="1"
android:text="+ -"
android:textAlignment="textEnd"
tools:ignore="HardcodedText,RtlSymmetry" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewVarianti"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_marginTop="5dp"
android:isScrollContainer="false"
android:scrollbars="vertical" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal"
tools:ignore="UselessParent">
<co.ceryle.segmentedbutton.SegmentedButtonGroup
android:id="@+id/segmentedButtonGroup"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:elevation="2dp"
app:sbg_backgroundColor="@color/green"
app:sbg_dividerColor="@color/white"
app:sbg_animateSelectorDuration="400"
app:sbg_dividerPadding="8dp"
app:sbg_dividerRadius="2dp"
app:sbg_dividerSize="2dp"
app:sbg_position="0"
app:sbg_radius="1dp"
app:sbg_rippleColor="@color/green"
app:sbg_selectorColor="@color/orange">
<co.ceryle.segmentedbutton.SegmentedButton
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
app:sb_drawable="@drawable/convar"/>
<co.ceryle.segmentedbutton.SegmentedButton
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
app:sb_drawable="@drawable/piu"/>
<co.ceryle.segmentedbutton.SegmentedButton
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
app:sb_drawable="@drawable/meno"/>
<co.ceryle.segmentedbutton.SegmentedButton
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
app:sb_drawable="@drawable/senza"/>
</co.ceryle.segmentedbutton.SegmentedButtonGroup>
</LinearLayout>
</LinearLayout>
通过在我的 AlertDialog 方法下面添加以下代码解决
dialog.getWindow().setBackgroundDrawableResource(R.color.semitransparent);
不知道为什么,但它通过增大 AlertDialog 解决了我的问题
实际上我的应用程序中有一个自定义的 AlertDialog,但我在其中实现了一个 SegmentButton 不适合 AlertDialog,如下面的屏幕所示。
显然,如果可能的话,我更愿意调整大小并使其适合 SegmentButton 中的元素,但如果不能的话,无论如何让整个 AlertDialog 变大都很棒
所以我想知道是否可以使该警告对话框的宽度更大。
这是我的 XML 自定义 AlertDialog
代码<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:gravity="center"
android:focusableInTouchMode="true"
android:background="#20d2d2d2"
android:orientation="vertical">
<TextView
android:id="@+id/deskART"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:text="VARIANTI"
android:textAlignment="center"
android:textColor="#008b58"
android:textSize="20sp"
android:textStyle="bold"
tools:ignore="HardcodedText" />
<SearchView
android:id="@+id/searchMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:iconifiedByDefault="false" />
<LinearLayout
android:id="@+id/TitleBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/desc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginEnd="2dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_weight="2"
android:text="Descrizione"
tools:ignore="HardcodedText" />
<TextView
android:paddingEnd="10dp"
android:id="@+id/preMeno"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:layout_weight="1"
android:text="+ -"
android:textAlignment="textEnd"
tools:ignore="HardcodedText,RtlSymmetry" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewVarianti"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_marginTop="5dp"
android:isScrollContainer="false"
android:scrollbars="vertical" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal"
tools:ignore="UselessParent">
<co.ceryle.segmentedbutton.SegmentedButtonGroup
android:id="@+id/segmentedButtonGroup"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:elevation="2dp"
app:sbg_backgroundColor="@color/green"
app:sbg_dividerColor="@color/white"
app:sbg_animateSelectorDuration="400"
app:sbg_dividerPadding="8dp"
app:sbg_dividerRadius="2dp"
app:sbg_dividerSize="2dp"
app:sbg_position="0"
app:sbg_radius="1dp"
app:sbg_rippleColor="@color/green"
app:sbg_selectorColor="@color/orange">
<co.ceryle.segmentedbutton.SegmentedButton
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
app:sb_drawable="@drawable/convar"/>
<co.ceryle.segmentedbutton.SegmentedButton
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
app:sb_drawable="@drawable/piu"/>
<co.ceryle.segmentedbutton.SegmentedButton
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
app:sb_drawable="@drawable/meno"/>
<co.ceryle.segmentedbutton.SegmentedButton
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
app:sb_drawable="@drawable/senza"/>
</co.ceryle.segmentedbutton.SegmentedButtonGroup>
</LinearLayout>
</LinearLayout>
通过在我的 AlertDialog 方法下面添加以下代码解决
dialog.getWindow().setBackgroundDrawableResource(R.color.semitransparent);
不知道为什么,但它通过增大 AlertDialog 解决了我的问题