如何设置 Android 的 onSearchRequested() 样式;
How to style Android's onSearchRequested();
我不知道如何使搜索对话框适合高度并看起来像操作栏(就像在 YouTube 上一样)。你能告诉我怎么做吗?
这是我的 Mainfest
<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);
我不知道如何使搜索对话框适合高度并看起来像操作栏(就像在 YouTube 上一样)。你能告诉我怎么做吗? 这是我的 Mainfest
<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);