问题
Hi now My app doesn't show ads and search view it used to show before but I created navigation menu and it doesn't show them anymore. Here is my code. I couldn't paste it here because stack overflow doesn't let me
MainActivity.java
https://pastebin.com/zVQCQRAc
ActivityMain.xml
https://pastebin.com/UUbStvE0
Appbar_main.xml
https://pastebin.com/4tR6B0Hm
Content_main.xml
https://pastebin.com/ipxy3gSU
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:background="#ededed"
android:paddingBottom="10dp">
<android.support.v7.widget.SearchView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/searchView"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/searchView"
android:descendantFocusability="blocksDescendants"
android:scrollbars="vertical"/>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="@string/banner">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
Also it would be a huge help if anyone could tell me how can show search in menu bar. Thanks.
回答1:
Try this to add SearchView
in Menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_search_album"
android:icon="@drawable/ic_search"
android:title="@string/str_search_album"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="collapseActionView|always" />
</menu>
than create a Searchable.xml in res-XMl
folder like this
Searchable.xml
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:hint="@string/search_trips"
android:label="@string/app_name" />
Than add this in your manifest file
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
add this code in Your Activity.java
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_album_search, menu);
final MenuItem item = menu.findItem(R.id.menu_search_album);
final SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);
searchView.setOnQueryTextListener(this);
return true;
}
For more Information How to Create a Search Interface
来源:https://stackoverflow.com/questions/47387247/adview-and-search-view-not-working