android实现与SearchView在活动中的下拉列表

时间:2016-06-29 10:13:56

标签: android searchview dropdown

在活动中,我使用 SearchView ,我想在发生任何结果时实施下拉可能吗?谢谢你。

searchActivity.java代码

protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search_activity);

    isSearchVisible = false;
    isHomeVisible = true;

    mActivity = this;
    mContext = getApplicationContext();

    mSearchView = (SearchView) findViewById(R.id.m_searchview);
    edtFromDate = (EditText) findViewById(R.id.edt_from_date);
    edtEndDate = (EditText) findViewById(R.id.edt_end_date);
    btnSearchNow = (Button) findViewById(R.id.btn_search_now);

    int searchPlateId = mSearchView.getContext().getResources()
            .getIdentifier("android:id/search_plate", null, null);
    View searchPlateView = mSearchView.findViewById(searchPlateId);
    if (searchPlateView != null) {
        searchPlateView.setBackgroundColor(Color.WHITE);
    }

}

search_activity.xml代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="@color/main_background"
android:layout_height="match_parent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_margin="@dimen/activity_horizontal_margin">

    <SearchView android:id="@+id/m_searchview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:closeIcon="@drawable/close"
        android:searchIcon="@drawable/search_blue"
        android:padding="2dp"
        android:background="@drawable/editext_background"
        android:layout_marginBottom="@dimen/activity_horizontal_margin"/>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/title_from_date"
            android:textSize="20sp"
            android:textColor="@color/colorAccent"
            android:layout_marginBottom="15dp"/>

        <EditText android:id="@+id/edt_from_date"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:drawableRight="@drawable/calendar"
            android:paddingRight="20dp"
            android:enabled="false"
            style="@style/loginEditTextView"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/title_end_date"
            android:textSize="20sp"
            android:textColor="@color/colorAccent"
            android:layout_marginBottom="15dp"/>

        <EditText android:id="@+id/edt_end_date"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:drawableRight="@drawable/calendar"
            android:paddingRight="20dp"
            android:enabled="false"
            style="@style/loginEditTextView"/>

    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <Button android:id="@+id/btn_search_now"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:background="@drawable/search_now"/>

    </RelativeLayout>

  </LinearLayout>

</LinearLayout>

这是清单应用程序的清单代码

<activity android:name=".activity.SearchActivity"
        android:label="@string/title_search_activity"
        android:configChanges="orientation"></activity>

0 个答案:

没有答案