android - How can I use a custom font in the input area of an input method? -
we're developing app need use custom font (a typeface loaded app's assets) in edittext. android input method docs state following:
when input focus moves or out of editable text field, android shows or hides input method (such on-screen keyboard) appropriate. system makes decisions how ui , text field appear above input method. example, when vertical space on screen constrained, text field might fill space above input method.
it's part in bold tripping up. phrase “the text field might fill...” appears misleading, in text field that's used not edittext set our custom font. (note: answers far explain how set custom font in edittext. we setting custom typeface in edittext. please read question before answering.) here's screenshot input method hidden:

here's happens when soft keyboard showing , vertical space constrained:

as can see, font in text field above input method not our custom font (i'm guessing it's system's default roboto font). happening every soft keyboard we've tried input method.
i want emphasize when space constrained, view above keyboard generated internally system, not of our code.
the main question is: there way (and, if so, it?) control appearance of (for lack of better terminology) proxy view—at minimum use our custom font?
it added bonus if control layout , appearance of entire proxy area above keyboard (including "done" button). using variation of technique described in this thread have our activity use locale different 1 set in system, activity's locale isn't being applied here. (if were, button on left , read "בוצע", happen if change device's locale hebrew. [edit: can correct button label using android:imeactionlabel attribute on edittext. however, don't know how control layout directionality.])
edit per request, here's how i'm constructing dialog (relevant parts excerpted dialogfragment):
public dialog oncreatedialog(bundle savedinstancestate) { final dialog dlg = new dialog(getactivity(), android.r.style.theme_holo_light_dialog_noactionbar); dlg.setcontentview(r.layout.edit_note_dialog); manimator = (viewanimator) dlg.findviewbyid(r.id.animator); final typeface hebrew = systemdata.gethebrewfont(); mnoteeditor = (edittext) dlg.findviewbyid(r.id.note_field); mnoteeditor.settypeface(hebrew); // etc. (setting fonts other elements, adding listeners, etc.) } and here's layout:
<?xml version="1.0" encoding="utf-8"?> <viewanimator xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/animator" android:layout_width="match_parent" android:layout_height="match_parent" > <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:paddingtop="10dp" android:text="@string/loading" /> <relativelayout android:layout_width="match_parent" android:layout_height="match_parent" > <textview android:id="@+id/title" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:background="@android:color/black" android:gravity="center" android:text="@string/edit_note_title" android:textcolor="@android:color/white" android:textsize="20sp" /> <textview android:id="@+id/citation" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/title" android:layout_centerhorizontal="true" android:background="@android:color/black" android:gravity="center" android:textcolor="@android:color/white" android:textsize="16sp" /> <linearlayout android:id="@+id/actions" style="?android:attr/buttonbarstyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_centerhorizontal="true" android:layout_margin="5dp" > <button android:id="@+id/cancel" style="?android:attr/buttonbarbuttonstyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginstart="8dp" android:gravity="center" android:minwidth="32dp" android:text="@string/cancel" android:textsize="@dimen/nav_interior_item_size" /> <button android:id="@+id/close" style="?android:attr/buttonbarbuttonstyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginend="8dp" android:gravity="center" android:minwidth="32dp" android:text="@string/save" android:textsize="@dimen/nav_interior_item_size" /> </linearlayout> <button android:id="@+id/undo" style="?android:attr/buttonbarbuttonstyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_alignparentstart="true" android:layout_margin="5dp" android:text="@string/edit_note_undo" android:textsize="@dimen/nav_interior_item_size" /> <button android:id="@+id/redo" style="?android:attr/buttonbarbuttonstyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_alignparentend="true" android:layout_margin="5dp" android:text="@string/edit_note_redo" android:textsize="@dimen/nav_interior_item_size" /> <edittext android:id="@+id/note_field" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_above="@+id/actions" android:layout_below="@+id/citation" android:focusableintouchmode="true" android:gravity="top" android:hint="@string/edit_note_hint" android:imeactionlabel="@string/done" android:inputtype="textmultiline|textnosuggestions" android:linespacingmultiplier="1.2" /> </relativelayout> </viewanimator>
it simple if had instance of inputmethodservice. there way set theme or set extracted view.
the problem have create custom implementation of input method , users have select in system settings.
update:
you can try with:
-
android:windowsoftinputmode="adjustresize"- make view scrollable
or
- use ime_flag_no_extract_ui
- set
oneditoractionlisteneronedittexthave action button on keyboard. - create custom layout or hide/show elements when screen's height small. example hide buttons @ bottom , show buttons on right side. can similar default extract view.
layout listener dialog or edittext:
mviewcontainer.getviewtreeobserver().addongloballayoutlistener(new viewtreeobserver.ongloballayoutlistener() { @override public void ongloballayout() { //unregister layout listener if needed. int heightpixels = mviewcontainer.getheight(); resources resources = mcontext.getresources(); int heightdip = (int) typedvalue.applydimension(typedvalue.complex_unit_dip, heightpixels, resources.getdisplaymetrics()); if (heightdip < min_height) { mbottombuttons.setvisibility(view.gone); msidebuttons.setvisibility(view.visible); } else { mbottombuttons.setvisibility(view.visible); msidebuttons.setvisibility(view.gone); } } }); changing visibility gone request relayout , listener run again can lead loop.
Comments
Post a Comment