android - Setting background color of a button changes the size of button -
i creating alert dialog on clicking imageview .code given below:
imgeditstatus.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { alertdialog.builder builder = new alertdialog.builder(profileactivity.this); inflater = (layoutinflater) getapplicationcontext().getsystemservice(context.layout_inflater_service); view dialogview = inflater.inflate(r.layout.dialog_edit_status, null); builder.setview(dialogview); dialog = builder.create(); dialog.show(); final edittext edtstatus = (edittext) dialogview.findviewbyid(r.id.editstatus); button btnok = (button) dialogview.findviewbyid(r.id.btnok); // btnok.getbackground().setcolorfilter(getresources().getcolor(r.color.orange_color)), porterduff.mode.src_atop); btnok.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { // toast.maketext(getapplicationcontext(), "ok clicked", toast.length_short).show(); string statustext = edtstatus.gettext().tostring().trim(); new updatestatustask().execute(statustext); } }); button btncancel = (button) dialogview.findviewbyid(r.id.btncancel); btncancel.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { toast.maketext(getapplicationcontext(), "cancel clicked", toast.length_short).show(); dialog.dismiss(); } }); } });
dialog_edit_status.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <edittext android:id="@+id/editstatus" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margintop="@dimen/margin20" android:hint="enter status here" android:paddingbottom="@dimen/padding10" android:padding="@dimen/padding10" android:textcolor="@color/black_color" android:textcolorhint="@color/gray_color" android:layout_marginbottom="@dimen/margin10"/> <relativelayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="@dimen/margin10"> <button android:id="@+id/btnok" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_marginleft="@dimen/margin50" android:text="ok" android:background="@color/orange_color" android:textcolor="@color/white_color"/> <button android:id="@+id/btncancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentright="true" android:layout_marginright="@dimen/margin50" android:text="cancel" android:textcolor="@color/white_color"/> </relativelayout> </linearlayout>
i trying set orange color in background of ok button.but size got changed. tried use following code :
btnok.getbackground().setcolorfilter(getresources().getcolor(r.color.orange_color)), porterduff.mode.src_atop);
it giving me error :setcolorfilter() in drawable can not applied (int) . please me fix issue
if want change background color retain other styles, below might help.
btnok.getbackground().setcolorfilter(contextcompat.getcolor(this, r.color.coloraccent), porterduff.mode.multiply);
Comments
Post a Comment