Customizing android DialogFragment -
iam beginner level programmer in android.now iam after small app development , have dialogfragment.everything working , displaying dialog box also.but have difficulties color scheme. have changed background color of layout , title bar color remains same white , title text color blue , blue line under that(need change green).how can achieve this? please me
here fragment code
public class clientinfofrag extends dialogfragment { public clientinfofrag() { } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater.inflate(r.layout.clientinfolayout, container); getdialog().settitle("client info"); return view; } }
thank you
since using .settitle()
method setting title defualt settings, such white background. if want customize title background color need have xml that. also, dialogfragments, knowledge , experience, should use public dialog oncreatedialog
instead of public view oncreateview
. way return dialog opposed view can call .show()
on , display dialog. here example:
@override public dialog oncreatedialog(bundle savedinstancestate) { alertdialog.builder builder = new alertdialog.builder(getactivity()); layoutinflater inflater = getactivity().getlayoutinflater(); bundle args = getarguments(); currentname = args.getstring(arg_current_name); builder.setview(inflater.inflate(r.layout.name_dialog, null)); builder.settitle("rename rapper program"); builder.setmessage("enter new name " + currentname + ":"); builder.setpositivebutton("rename", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int which) { newname = (edittext) getdialog().findviewbyid(r.id.new_name); newprogname = newname.gettext().tostring(); mrename.renameprogram(currentname, newprogname); } }); builder.setnegativebutton("cancel", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int which) { dismiss(); } }); return builder.create(); }
here example dialog xml, though not xml being inflated in above dialogfragment:
<?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="wrap_content"> <textview android:drawableleft="@drawable/login" android:layout_width="match_parent" android:layout_height="64dp" android:background="#fcd116" android:text="@string/login" android:textsize="36sp"/> <edittext android:id="@+id/username" android:inputtype="textemailaddress" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margintop="16dp" android:layout_marginleft="4dp" android:layout_marginright="4dp" android:layout_marginbottom="4dp" android:hint="@string/un"/> <edittext android:id="@+id/password" android:inputtype="textpassword" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margintop="4dp" android:layout_marginleft="4dp" android:layout_marginright="4dp" android:layout_marginbottom="16dp" android:fontfamily="sans-serif" android:hint="@string/pw"/> </linearlayout>
the linearlayout
setting rest of child items placed accordingly. first textview
acts "title" bar , edittext
s "body" of dialog. have no buttons in xml because set programmatically within oncreatedialog
in other snippet of code above.