Android Custom ActionBar with Search View

做~自己de王妃 提交于 2019-12-01 12:19:06

问题


I am using custom ActionBar library in my Android App. there i want to show a searchView but can not find any solution, i m working in library that is
https://github.com/johannilsson/android-actionbar

This is a class

private class ExampleAction extends AbstractAction {

        public ExampleAction() {
            super(R.drawable.ic_title_export_default);
        }

        @Override
        public void performAction(View view) {
            Toast.makeText(OtherActivity.this, "Example action",
                    Toast.LENGTH_SHORT).show();
        }

    }
    //use for signle action how to use for multiactions
       ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar);
       actionBar.addAction(new ExampleAction());


actually i found code for searchbar but it is in .cs format how to use this searchview
https://github.com/zleao/MonoDroid.ActionBar

Thanks bro & sis


回答1:


Take a look at this answer. According to this answer SearchView is available support library. add dependency to build.gradle

compile 'com.android.support:appcompat-v7:22.0.0'

and make imports

import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.SearchView;

According to this answer it worked on API 8 on emulator. For more details, check the link with the question and answer itself. Hope it helps.

UPDATE

By adding this code

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:hmkcode="http://schemas.android.com/apk/res-auto">
<item
    android:id="@+id/action_search"
    android:orderInCategory="100"
    hmkcode:showAsAction="always"
    android:icon="@drawable/ic_action_search"
    android:title="Search"/>
<item
    android:id="@+id/action_copy"
    android:orderInCategory="100"
    hmkcode:showAsAction="always"
    android:icon="@drawable/ic_content_copy"
    android:title="Copy"/>
<item
    android:id="@+id/action_share"
    android:orderInCategory="100"
    hmkcode:showAsAction="always"
    android:icon="@drawable/ic_social_share"
    android:title="Share"/>

you can achieve this:

You can customize items in the way you want. For more details see this example.



来源:https://stackoverflow.com/questions/29815192/android-custom-actionbar-with-search-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!