Android - Make AlertDIalog buttons a uniform size -


i have alert dialog positive , negative button added programatically. in dialog layout there 2 buttons, above alertdialog's native buttons.

dialog

when these 2 right next each other, realized in dialog, native positive/negative/neutral buttons not equally weighted. content of text determines horizontal weight, rather each taking 50% (or 33% if 3 buttons) of dialog. in case, negative button's text longer positive button's text, looks image posted above.

i can't find way fix this, have idea?

thanks!

xml requested:

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"                 android:layout_width="match_parent"                 android:layout_height="match_parent" >      <textview android:id="@+id/rcd_msg"               android:layout_width="wrap_content"               android:layout_height="wrap_content"               android:layout_centerhorizontal="true"               android:layout_margin="8dp"               android:text="@string/rating_dialog_text"               android:textsize="14dp"               android:textcolor="@android:color/white"               android:gravity="center"/>      <ratingbar android:id="@+id/rcd_rating_bar"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_below="@id/rcd_msg"                android:layout_margin="8dp"                android:paddingbottom="10dp"                android:numstars="5"                android:rating="0"                android:layout_centerhorizontal="true"/>      <relativelayout android:layout_height="56dp"                     android:layout_width="match_parent"                     android:layout_below="@id/rcd_rating_bar">          <linearlayout android:layout_width="match_parent"                       android:layout_height="match_parent"                       android:orientation="horizontal">              <relativelayout android:id="@+id/rcd_image"                             android:layout_width="0dp"                             android:layout_height="fill_parent"                             android:background="@color/selectable_transparent"                             android:layout_weight="1">                  <textview android:id="@+id/rcd_image_text"                           android:layout_height="wrap_content"                           android:layout_width="wrap_content"                           android:layout_centerinparent="true"                           android:paddingleft="0dp"                           android:gravity="center"                           android:text="@string/add_image"                           android:textcolor="@android:color/white"                           android:textsize="16sp"                           android:clickable="true"/>                  <imageview android:id="@+id/rcd_image_img"                            android:layout_height="32dp"                            android:layout_width="32dp"                            android:layout_centervertical="true"                            android:layout_margin="8dp"                            android:layout_toleftof="@id/rcd_image_text"                            android:scaletype="centerinside"                            android:src="@android:drawable/ic_menu_camera"/>              </relativelayout>              <relativelayout android:id="@+id/rcd_comment"                             android:layout_width="0dp"                             android:layout_height="fill_parent"                             android:background="@color/selectable_transparent"                             android:layout_weight="1">                  <textview android:id="@+id/rcd_comment_text"                           android:layout_height="wrap_content"                           android:layout_width="wrap_content"                           android:layout_centerinparent="true"                           android:paddingright="6dp"                           android:gravity="center"                           android:text="@string/add_comment"                           android:textcolor="@android:color/white"                           android:textsize="16sp"                           android:clickable="true"/>                  <imageview android:id="@+id/rcd_comment_img"                            android:layout_height="32dp"                            android:layout_width="32dp"                            android:layout_centervertical="true"                            android:layout_margin="4dp"                            android:layout_torightof="@id/rcd_comment_text"                            android:scaletype="centerinside"                            android:src="@drawable/ic_menu_comment"/>              </relativelayout>          </linearlayout>          <linearlayout android:layout_width="1dp"                       android:layout_height="38dp"                       android:layout_centerhorizontal="true"                       android:layout_alignparentbottom="true"                       android:orientation="horizontal"                       android:layout_margin="10dp"                       android:background="@color/transparent_white" />      </relativelayout>  </relativelayout> 

figured out solution... don't know why didn't think of before.

i following:

mrateconcertdialog.setonshowlistener(new onshowlistener() {      @override     public void onshow(dialoginterface d) {         button posbutton = mrateconcertdialog.getbutton(dialoginterface.button_positive);         button negbutton = mrateconcertdialog.getbutton(dialoginterface.button_negative);          layoutparams posparams = (layoutparams) posbutton.getlayoutparams();         posparams.weight = 1;         posparams.width = layoutparams.match_parent;          layoutparams negparams = (layoutparams) negbutton.getlayoutparams();         negparams.weight = 1;         negparams.width = layoutparams.match_parent;          posbutton.setlayoutparams(posparams);         negbutton.setlayoutparams(negparams);     } }); 

basically, have manipulate size of buttons after dialog shown. create onshowlistener , can set weights , widths way. comments, hope can in future.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -