AdView和搜索视图不起作用 [英] AdView and search view not working

查看:121
本文介绍了AdView和搜索视图不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在您好我的应用程序没有显示广告和以前显示过的搜索视图,但是我创建了导航菜单,并且不再显示它们。这是我的代码。我无法将其粘贴到此处,因为堆栈溢出不允许我



MainActivity.java



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 />

比在清单文件中添加

 <元数据
android:name = android.app.searchable
android:resource = @ xml / searchable />

将此代码添加到Your Activity.java

  @Override 
public boolean onCreateOptionsMenu(Menu menu){
getMenuInflater()。inflate(R.menu.menu_album_search,menu);

最终的MenuItem项目= menu.findItem(R.id.menu_search_album);
final SearchView searchView =(SearchView)MenuItemCompat.getActionView(item);

searchView.setOnQueryTextListener(this);
返回true;

}

更多信息 如何创建搜索界面


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.

解决方案

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

这篇关于AdView和搜索视图不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆