以下をチェックしてください: 電話の検索ボタンをクリックしても何も起こらないようにする方法は?
しかし、それは私にはうまくいきません。他に提案はありますか?ありがとうございました。Phil の提案に従って、彼の回答に従ってコードを更新します。バグを表示http://www.youtube.com/watch?v=9lekcH1JAf0&feature=youtu.be
というわけで、サンプルプロジェクトを作りました。Android バージョン 2.3.5 と 4.1 の 2 つの異なる携帯電話でこれをテストしました。また、エミュレータ バージョン 2.2 でもテストしました。ボタン表示ダイアログをクリックすると、進行状況ダイアログが正常に表示され、引き続き表示されます。ただし、電話とエミュレーターで [検索] ボタンをクリックすると、進行状況ダイアログが消えます。これがクラスで、マニフェストが続きます。
現在の動作では、検索ボタンをクリックすると進行状況ダイアログが消えます。期待または必要な動作は、検索ボタンを無効にすることです。または、同様に、ダイアログが表示されているときに検索ボタンがクリックされた場合、このクリックによってダイアログが消えることはありません。
package com.example.test6;
import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
Button showDialogButton;
Context context;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showDialogButton = (Button) findViewById(R.id.showDialogButton);
showDialogButton.setOnClickListener(showDialog);
context = this;
startSearch(null, false, null, false);
}
private OnClickListener showDialog = new OnClickListener() {
@Override
public void onClick(View v) {
ProgressDialog progressDialog = new ProgressDialog(context);
progressDialog.show();
}
};
@Override
public boolean onSearchRequested() {
Log.d("onSearchRequested", "search key pressed");
return false;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test6"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="1"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="Test6" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
</application>
</manifest>
私の検索可能なxmlは、提供された参照によると、 res/xml/searchable.xml にあります。これは私の searchable.xml がどのように見えるかです:
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:searchSuggestAuthority="dictionary"
android:searchSuggestIntentAction="android.intent.action.VIEW"
android:includeInGlobalSearch="true">
</searchable>