2016-11-21 6 views
1

私は私の手に奇妙な問題があります。私は、SearchViewウィジェットのヒントテキストを垂直方向にセンタリングして、虫めがねとクローズアイコンに揃えるようにする必要があります。しかし、私はこれが右に近いアイコンと完全に整合していることがわかりました、コメントアウト行で虫眼鏡を動かさずに、SearchViewのヒントテキストのみをどのように整列させるのですか?

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(); 

This is what the SearchView currently looks like. Notice how the text view is vertically off centered in comparison to the magnifying glass and the x icon

ここで私がこれまで持っているものの抜粋です虫眼鏡のアイコンが消えます。私はhttp://nlopez.io/how-to-style-the-actionbar-searchview-programmatically/

はしかし、これがヒントテキストと虫眼鏡の両方を移動し、他のいくつかの奇妙なものをしたこの資料に記載されている、リフレクションを使用してみました。私の観察から、上記のコード(私はアンドロイドコードベースから精査しました)では、虫眼鏡は実際にヒントテキストに結びついているようですが、虫眼鏡はそれ自身のものだと思われますか?私は虫眼鏡IDからImageViewを作成するなど、それを試してみることにしました。しかし何もそれから出て来なかった。

+0

虫眼鏡は 'ImageSpan'ですので、ヒントテキストに結びついています。 – Karakuri

+0

私は何を求めているのですか?虫眼鏡をそのままにしてヒントテキストを移動しますか? – David

答えて

0

私はこのプロジェクトを数ヶ月間中断した後、私自身の質問に答えるべきだと感じました。私は間違った質問をしていましたが、上記のコメントの後に "虫めがねはImageSpanなので、ヒントテキストに結びついています。"

実際の答えは、画像の周囲にテキストを揃えることです。それに答えがあります!リンクはここにあります:Align text around ImageSpan center vertical

関連する問題