android - 如何设置 Android 的 onSearchRequested() 样式;

标签 android search android-activity styles

我不知道如何使搜索对话框适合高度并看起来像操作栏(就像在 YouTube 上一样)。你能告诉我怎么做吗? 这是我的主要节日

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="info.at_soft.zapiskiinfo" >

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name">
        <intent-filter>
            <category android:name="android.intent.category.LAUNCHER" />
            <action android:name="android.intent.action.MAIN" />
        </intent-filter>
    </activity>

    <activity android:name=".SearchableActivity" android:launchMode="singleTop" >
        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
        </intent-filter>
        <meta-data android:name="android.app.searchable" android:resource="@xml/searchable"/>
    </activity>

    <meta-data android:name="android.app.default_searchable" android:value=".SearchableActivity"/>
</application>

点击按钮时的代码:

private void openSearch(){
    onSearchRequested();
    Toast.makeText(this, "Test", Toast.LENGTH_LONG).show();
}

这也是我的 styles.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

</style>
</resources>

请看这张照片: http://imgur.com/zhXmUSe

如何让它看起来像这样:http://imgur.com/nlCY0ES

最佳答案

在 Activity 的 OnCreate 中调用下面:

setHasOptionsMenu(true);
getActivity().getActionBar().setCustomView(R.layout.yourSearchBarLayout);

关于android - 如何设置 Android 的 onSearchRequested() 样式;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28831019/

相关文章:

java - 无法在 SettingsActivity 中解析 'AppCompatPreferenceActivity'

java - 如何判断我的 Android 应用程序正在使用哪些库?

Android、Skia 和硬件加速图形

PHP PDO MySQL 查询 LIKE -> 多个关键字

android - IllegalArgumentException - 状态参数 : 5 on BottomSheet

android - startActivityForResult(Intent intent, int requestCode, Bundle options) 如何检索额外的 bundle 选项?

android - 返回 Activity (但不是通过 finish())

java - 同时播放声音 Android

c - 如何快速对许多正则表达式键进行字符串匹配?

algorithm - 如何按位置和日期范围高效搜索大型数据集?