Cannot change the width of AlertDialog with custom view in Android -
i absolute beginner android. having problem setting width of default alertdialog custom view in android. not resizing width of alert dialog. please wrong code ?
this view layout of alert dialog
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="match_parent"> <android.support.v7.widget.appcompatbutton xmlns:app="http://schemas.android.com/apk/res-auto" android:textcolor="@color/white" app:backgroundtint="@color/green" android:layout_gravity="center_horizontal" android:id="@+id/btn_row_option_done" android:text="done" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <android.support.v7.widget.appcompatbutton android:textcolor="@color/white" xmlns:app="http://schemas.android.com/apk/res-auto" app:backgroundtint="@color/lightblue" android:layout_gravity="center_horizontal" android:text="edit" android:id="@+id/btn_row_option_edit" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <android.support.v7.widget.appcompatbutton android:textcolor="@color/white" xmlns:app="http://schemas.android.com/apk/res-auto" app:backgroundtint="@color/red" android:layout_gravity="center_horizontal" android:text="delete" android:id="@+id/btn_row_option_delete" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <android.support.v7.widget.appcompatbutton xmlns:app="http://schemas.android.com/apk/res-auto" app:backgroundtint="@color/white" android:layout_gravity="center_horizontal" android:text="cancel" android:id="@+id/btn_row_option_cancel" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </linearlayout>
as can see, set width of linearlayout wrap_content.
this how opening alert dialog in java code
public void showoptiondialog(final int id) { layoutinflater layoutinflater = layoutinflater.from(getactivity()); view view = layoutinflater.inflate(r.layout.row_option_dialog, null); final alertdialog alertdialog = new alertdialog.builder(getactivity()).create(); boolean istaskdone = dbhelper.istaskdone(id); button donebtn = (button)view.findviewbyid(r.id.btn_row_option_done); if(istaskdone==false) { donebtn.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { dbhelper.markasdone(id); refreshlistview(); alertdialog.cancel(); toast.maketext(getactivity().getbasecontext(),"marked done",toast.length_short).show(); } }); } else{ viewgroup viewgroup = (viewgroup)donebtn.getparent(); viewgroup.removeview(donebtn); } button editbtn = (button)view.findviewbyid(r.id.btn_row_option_edit); if(istaskdone==false) { editbtn.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { mainactivity activity = (mainactivity) getactivity(); activity.replaceedittaskfragment(id); alertdialog.cancel(); } }); } else{ viewgroup viewgroup = (viewgroup)editbtn.getparent(); viewgroup.removeview(editbtn); } button deletebtn = (button)view.findviewbyid(r.id.btn_row_option_delete); deletebtn.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { dbhelper.deletetask(id); items.remove(optionfocuseditemindex); adapter.notifydatasetchanged(); toast.maketext(getactivity().getbasecontext(),"task deleted",toast.length_short).show(); alertdialog.cancel(); updatelistemptytext(); } }); button cancelbtn = (button)view.findviewbyid(r.id.btn_row_option_cancel); cancelbtn.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { alertdialog.cancel(); } }); alertdialog.setview(view); alertdialog.show(); }
but when alert dialog opened, width not resized , still showing default size in screenshot.
this screenshot.
as can see, width full of screen did set wrap_content. set 300px. not working. please wrong width code , how can achieve ?
first make other layout container , inside make linear layout wrap content. after can make alpha background of container 0 transparent. dialog inside buttons on inner layout. custom dialog cant use alertdialog, make own activity behavior dialog.
Comments
Post a Comment