繁体   English   中英

如何在不移动放大镜的情况下仅对齐SearchView的提示文本?

[英]How do I align ONLY the hint text of a SearchView without moving the magnifying glass?

我手上有一个奇怪的问题。 我需要能够垂直居中SearchView小部件的提示文本,以便它与放大镜和关闭图标对齐。

这就是SearchView目前的样子。 请注意文本视图与放大镜和x图标相比如何垂直偏离居中

这是我到目前为止的一小部分:

SearchView sv = (SearchView) view.findViewById(R.id.search);

int id = sv.getContext().getResources().getIdentifier("android:id/search_src_text", null, null); 
int searchPlate = sv.getContext().getResources().getIdentifier("android:id/search_plate", null, null); 
int searchMagIcon = sv.getContext().getResources().getIdentifier("android:id/search_mag_icon", null, null); 
ImageView magIcon = (ImageView) sv.findViewById(searchMagIcon); View searchPlateView = sv.findViewById(searchPlate); 
EditText searchText = (EditText) sv.findViewById(id); searchText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);

//searchText.setHint("Some test hint text here"); 
searchPlateView.setBackgroundColor(Color.WHITE); 
searchText.setHintTextColor(Color.parseColor("#D8D8D8")); 
sv.setIconified(false); 
sv.clearFocus();

在注释掉的行中,我发现它与右边的关闭图标完美对齐,然而,这摆脱了放大镜图标。 我尝试过使用反射,本文中概述了http://nlopez.io/how-to-style-the-actionbar-searchview-programmatically/

然而,这移动了提示文本和放大镜,并做了一些其他奇怪的东西。 根据我的观察,似乎放大镜实际上与提示文本相关联,虽然在上面的代码中(我从android代码库中搜索过),似乎放大镜是它自己的东西? 我试图玩它,例如从放大镜id创建一个ImageView。 但没有任何结果。

经过几个月的中断,我觉得我应该回答我自己的问题。 我问了一个错误的问题,并且应该意识到在上面关于“放大镜是ImageSpan之后的评论,所以是的,它与提示文本相关联”。

对此的真正答案是,对齐图像范围内的文本。 而且有一个答案! 链接在此处: 对齐ImageSpan中心垂直周围的文本

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM