android - Toolbar+SearchView+textSelection = bad position of text selection bar -
background
i'm trying theme my app have more material design look, , such, have toolbar that's being set actionbar of activity.
i have searchview in allows search items of listview below.
the problem
thing is, can select text in searchview (to copy, cut, etc...), yet when happens, toolbar gets text-selection toolbar on top of it, making , text hidden:
before text selection:
after text selection:
what i've tried
i tried disable text selection using code:
final edittext searchtextview=(edittext)searchview.findviewbyid(r.id.search_src_text); if(searchtextview!=null&&version.sdk_int>=version_codes.honeycomb) searchtextview.settextisselectable(false);
but didn't anything. i've tried search how listen of text selection (so set toolbar margintop or something), didn't find it.
the thing have succeeded using code, tells me when text-selection toolbar appears (but not when disappears) :
searchtextview.setoncreatecontextmenulistener(new oncreatecontextmenulistener() { @override public void oncreatecontextmenu(final contextmenu menu,final view v,final contextmenuinfo menuinfo) { log.d("applog","oncreatecontextmenu"); } });
this doesn't help. can't close menu. think can't help, devices might show else instead of toolbar (like on lg devices, have small popup).
the code
the layout vertical linearlayout, first item toolbar:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v7.widget.toolbar android:id="@+id/activity_app_list__toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/colorprimary" android:colorcontrolnormal="?attr/colorcontrolnormal" android:minheight="?attr/actionbarsize" android:theme="?attr/actionbartheme" tools:ignore="unusedattribute"/> ...
the theme that's used set hide normal action bar:
<style name="apptheme" parent="@style/theme.appcompat.light.darkactionbar"> <item name="windowactionbar">false</item> <item name="windownotitle">true</item> ...
the action bar menu's xml quite basic , has 3 action items, first 1 of them searchview:
<item android:id="@+id/menuitem_search" android:icon="?attr/app_search_menu_icon" android:title="@string/search" app:actionviewclass="android.support.v7.widget.searchview" app:showasaction="always|collapseactionview"/>
handling searchview done via special class i've made supports old android versions. main function handles searchview :
@targetapi(build.version_codes.ice_cream_sandwich) public void init(final menuitem searchmenuitem,final int hintresid,final onquerytextlistener onquerytextlistener,final onactionexpandlistener onactionexpandlistener) { this._searchmenuitem=searchmenuitem; if(_searchview==null) { _searchview=(searchview)menuitemcompat.getactionview(searchmenuitem); if(_searchview==null) { menuitemcompat.setshowasaction(searchmenuitem,menuitem.show_as_action_collapse_action_view|menuitem.show_as_action_always); menuitemcompat.setactionview(searchmenuitem,_searchview=new searchview(_context)); } _searchview.setqueryhint(_context.getstring(hintresid)); if(version.sdk_int<version_codes.honeycomb) { final edittext searchtextview=(edittext)_searchview.findviewbyid(r.id.search_src_text); if(searchtextview!=null) { searchtextview.setscroller(new scroller(_context)); searchtextview.setmaxlines(1); searchtextview.setverticalscrollbarenabled(true); searchtextview.setmovementmethod(new scrollingmovementmethod()); final int searchtextcolorresid=app.getresidfromattribute(_context,android.r.attr.textcolorprimary); if(searchtextcolorresid!=0) searchtextview.settextcolor(_context.getresources().getcolor(searchtextcolorresid)); else { // todo workaround v2.3 devices can't correct color. remove when stopping support v2.3 textview searchbadge=(textview)_searchview.findviewbyid(r.id.search_badge); if(searchbadge!=null) searchtextview.settextcolor(searchbadge.gettextcolors()); } } } _searchview.setonquerytextlistener(onquerytextlistener); menuitemcompat.setonactionexpandlistener(searchmenuitem,onactionexpandlistener); } }
the function called @ end of "oncreateoptionsmenu" of activity/fragment supposed have searchview, example:
_searchholder.init(menu.finditem(r.id.menuitem_search),r.string.search_for_apps,onquerytextlistener,onactionexpandlistener);
the question
how can solve issue? has happened because toolbar view, text-selection bar shown on top of it, there way fix this?
how avoid toolbar become on top of 1 i've used?
is there way support devices in regard?
looking @ google's apps, seems don't use official searchview, 1 of own. on youtube seems official one, there seems if use official actionbar (plus has weird colors when selecting text).
i found in many apps(google messenger, contacts etc) text selection disabled in search view. can setting toolbar theme as.
<style name="toolbartheme" parent="@style/themeoverlay.appcompat.dark.actionbar"> <item name="android:autocompletetextviewstyle">@style/searchviewstyle</item> <item name="android:textcolor">@android:color/white</item> <item name="android:textcolorprimary">@android:color/white</item> <item name="android:edittextcolor">@android:color/white</item> </style> <style name="searchviewstyle" parent="@android:style/widget.holo.light.autocompletetextview"> <item name="android:longclickable">false</item> </style>
or if want youtube add line in theme
<item name="windowactionmodeoverlay">false</item>
Comments
Post a Comment