实际上,我的应用程序中有一个自定义的AlertDialog,但是我实现了一个SegmentButton,它不能正确显示在AlertDialog中,如下面的屏幕所示。
很明显,如果可能的话,我宁愿调整大小并使其仅来自SegmentButton,但如果不能的话,将整个AlertDialog变大还是很棒的
所以我想知道是否有可能使该警报对话框的宽度更大。
这是我的自定义AlertDialog的XML代码
<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>
答案 0 :(得分:0)
通过在我的AlertDialog方法下面添加以下代码来解决
dialog.getWindow().setBackgroundDrawableResource(R.color.semitransparent);
Idk为什么但它通过使AlertDialog变大解决了我的问题