简体   繁体   中英

How to make an Custom Alert Dialog width larger?

Actually i have a custom AlertDialog in my app, but i've implemented in it an SegmentButton that is not fitting properly in the AlertDialog as you can see on the screen below.

Obviously i would prefer to resize and make fit the elements from just the SegmentButton if it's possible but if not it would be anyway great to make the entire AlertDialog larger

在此处输入图片说明

So i would know if is it possible to make that alert Dialog larger in width.

Here is my XML code for the custom 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>

Solved by adding the following code below my AlertDialog method

 dialog.getWindow().setBackgroundDrawableResource(R.color.semitransparent);

Idk why but it solved my problem by making AlertDialog larger

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM