在动作条搜索查看可绘制出现模糊 [英] SearchView drawables in ActionBar appear blurred

查看:163
本文介绍了在动作条搜索查看可绘制出现模糊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的菜单布局为我的动作条:

I have the following menu layout for my ActionBar:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item 
        android:id="@+id/itemSearch"
        android:icon="@drawable/actionbar_icon_search"
        android:showAsAction="ifRoom|collapseActionView"
        android:actionViewClass="android.widget.SearchView" 
        android:title="Search"/>
</menu>

和这里的设置code:

And here's the setup code:

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.actionbar_default, menu);

    SearchView searchView=(SearchView) menu.findItem(R.id.itemSearch).getActionView();
    int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
    View searchEditText = searchView.findViewById(searchPlateId); 
    ((TextView) searchEditText).setTextColor(Color.WHITE);
    searchView.setOnCloseListener(new OnCloseListener() {...});
    searchView.setOnQueryTextListener(new OnQueryTextListener() {...});
}

一切正常,除了一件事:我的华硕平板(TF-201的Andr​​oid 3.2.1)图形模糊:

Everything is ok, except for one thing: on my Asus tablet (TF-201, Android 3.2.1) graphics are blurred:

如果我删除的android:actionViewClass =android.widget.SearchView,一切看起来正常的:

If I remove android:actionViewClass="android.widget.SearchView", everything looks normal:

这问题不是复制在4.1.2模拟器。我试过只留下菜单通胀code在我的 onCreateOptionsMenu()但这并没有帮助。

This problem is not reproduced on 4.1.2 emulator. I tried leaving only menu inflation code in my onCreateOptionsMenu() but that didn't help.

如何解决这个问题?

推荐答案

于是我一掌解决方案,但是,它宣称权兼容性仅适用于API 14以上,如果不使用ActionBarSherlock库。

So I beat up the solution, however, it declares right compatibility only for API 14 and above, if not using ActionBarSherlock library.

重要的是要连接到的为主题背景应用程序,否则,你得到搜索查看最低的设计(模糊的图标)

Important is to be connected to Themed Context of application, otherwise you get lowest possible design for SearchView (blurry icons)

创建搜索查看编程

片段

SearchView searchView =
                new SearchView(getActivity().getActionBar().getThemedContext());

活动

SearchView searchView = new SearchView(getActionBar().getThemedContext());

第二类解决方案(ABS兼容性,API 8 +)

操作栏福尔摩斯片段

SearchView searchView = 
  new SearchView(getSherlockActivity().getSupportActionBar().getThemedContext());

操作栏福尔摩斯活动

SearchView searchView = new SearchView(getSupportActionBar().getThemedContext());


解决方案三(API 11 +)

在某些情况下,设置 SearchView.setBackgroundColor(INT颜色),使图标显得不那么模糊,尝试 Col​​or.WHITE Color.BLACK


Third solution (API 11+)

In some cases, setting SearchView.setBackgroundColor(int color) makes the icon appear less blurry, try Color.WHITE or Color.BLACK

注意这改变背景颜色菜单项是否倒塌或没有,例如。通过使用主题Holo.Light.DarkActionBar你需要使用正确的颜色,根据你的动作条的风格。

Note that this changes background color for MenuItem whether collapsed or not, and eg. by using Theme Holo.Light.DarkActionBar you need to use right color, according to your ActionBar style.

这篇关于在动作条搜索查看可绘制出现模糊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆