2013-01-24 63 views
0

是否可以將搜索對話框固定在應用程序活動的頂部?Android搜索對話框始終可見

問題是我的是,如果用戶點擊活動中的其他位置,錯誤地說,搜索對話框關閉,用戶必須點擊搜索電話按鈕。

由於我的示例應用程序是一個搜索應用程序,我希望它始終在我的活動頂部可見。

有沒有辦法,android API允許這樣嗎?

感謝

編輯與代碼:

public class MainActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     onSearchRequested(); 

     Intent intent = getIntent(); 

     if (Intent.ACTION_SEARCH.equals(intent.getAction())) { 
       String query = intent.getStringExtra(SearchManager.QUERY); 

       Log.d("search", query); 
     } 

    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.activity_main, menu); 
     return true; 
    } 

活動:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity" > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:text="@string/hello_world" /> 

</RelativeLayout> 

searchconfig

<?xml version="1.0" encoding="utf-8"?> 
<searchable xmlns:android="http://schemas.android.com/apk/res/android" 
     android:label="@string/app_name" > 
</searchable> 

回答

0

既然你控制什麼其他有您的活動,您可以Ë確保沒有其他元素是可點擊/可聚焦的(您的搜索字段除外)。

無論如何,如果您向我們展示您遇到問題的實際代碼,我們可能會更有幫助。

+0

謝謝斯蒂芬,我已經添加了我的示例POC中的代碼。 – Cavish

+0

Infact,我希望它在應用程序開始以及結果活動(列表活動)的情況下可見。但是軟鍵只有在對話框處於活動狀態時纔會出現,(點擊)您可以讓我知道如何做到這一點? – Cavish

+0

或者..是否有可能把這個Android默認搜索對話框放在一個單獨的佈局中並且始終顯示,而不管在活動中被點擊什麼? 如果可以,請讓我知道如何做到這一點,使用上述佈局我有什麼? 謝謝 – Cavish