2015-04-23 75 views
1

我使用自定义的动作条库在我的Android应用程序。在那里,我想显示搜索查看,但无法找到任何解决方案,即时通讯在图书馆工作是
https://github.com/johannilsson/android-actionbar

这是一类Android的自定义动作条与搜索查看

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()); 


其实我发现代码搜索栏但它是.cs格式如何使用此搜索视图
https://github.com/zleao/MonoDroid.ActionBar

感谢兄弟& sis

+0

您可以使用在Android http://developer.android.com/guide/topics/search/search-dialog.html将只需更换您的自定义视图'ActionBar'时'用行动Intent''SEARCH'搜索请求 – Yurets

+0

感谢兄弟,它需要api级别11,但我正在api级别8上工作。所以我们需要像上面提到的那样。 – Attaullah

+1

您需要使用支持库的向后兼容性 – Pankaj

回答

2

看看这个answer。 根据这个答案SearchView是可用的支持库。 添加依赖关系build.gradle

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

,使进口

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

根据这个答案,它的工作在API 8模拟器。有关更多详细信息,请查看问题链接并自行解答。 希望它有帮助。

UPDATE

通过添加该代码

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

你可以做到这一点:

enter image description here

您可以自定义你想要的方式的项目。欲了解更多详情,请参阅此example

+0

兄弟,我需要这样的 http://shambhai.comuf.com/BottomAction_Overflow.png – Attaullah

+0

@AttaullahKhan,我更新了答案,看一看。我认为它看起来与你的要求相似。我发现了一个更类似的例子,http://antonioleiva.com/actionbarcompat-how-to-use/,所以我认为它依赖于你自定义项目的方式,问题不再是兼容性,所以如果你满意在API 8上实现兼容性的方式,请接受答案,问题将被关闭。 – Yurets

+1

我用我自己提到的库,但这也适用于我,谢谢 @Yurets – Attaullah