特性queryHint和iconifiedByDefault不工

特性queryHint和iconifiedByDefault不工

本文介绍了Android的支持库搜索查看XML特性queryHint和iconifiedByDefault不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个布局文件下面搜索查看

I have the following SearchView in a layout file

<android.support.v7.widget.SearchView
    android:id="@+id/search_view"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:queryHint="@string/search"
    android:iconifiedByDefault="false"

     />

然而,当我跑我的应用程序没有一丝出现,搜索查看图标化,在code它的工作原理我的问题是,这是在supportlibrary一个错误?

However when i run my application no hint appears and the searchview is iconified, in code it works my question is is this a bug on the supportlibrary ?

推荐答案

您缺少必需的命名空间。替换 [yourapp] 在XML布局你的应用程序名称。使用此命名空间搜索查看属性。如果你使用的支持库的意见这种做法是必要的。顺便说一句。你必须做同样的menu对于AppCompat行动吧。

You are missing required namespace. Replace [yourapp] with your app name in XML layout. Use this namespace for SearchView properties. This approach is necessary if you use views from support library. Btw. you must do the same with menu for AppCompat action bar.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:[yourapp]="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.SearchView
        android:id="@+id/fragment_address_search"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/global_bg_front"
        android:textSize="@dimen/global_text_medium"
        android:textColor="@color/global_text_primary"
        [yourapp]:queryHint="@string/fragment_address_search_hint"
        [yourapp]:iconifiedByDefault="false" />

</LinearLayout>

您还可以设置你的搜索查看编程。请参阅我的template在GitHub上的。

You can also setup your SearchView programmatically. See my template on GitHub.

private void setupSearchView(SearchView searchView)
{
    // search hint
    searchView.setQueryHint(getString(R.string.fragment_address_search_hint));

    // background
    View searchPlate = searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
    searchPlate.setBackgroundResource(R.drawable.searchview_bg);

    // icon
    ImageView searchIcon = (ImageView) searchView.findViewById(android.support.v7.appcompat.R.id.search_mag_icon);
    searchIcon.setImageResource(R.drawable.searchview_icon);

    // clear button
    ImageView searchClose = (ImageView) searchView.findViewById(android.support.v7.appcompat.R.id.search_close_btn);
    searchClose.setImageResource(R.drawable.searchview_clear);

    // text color
    AutoCompleteTextView searchText = (AutoCompleteTextView) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
    searchText.setTextColor(getResources().getColor(R.color.global_text_primary));
    searchText.setHintTextColor(getResources().getColor(R.color.global_text_secondary));
}

这篇关于Android的支持库搜索查看XML特性queryHint和iconifiedByDefault不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 17:06