2015-04-23 33 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