###前提・実現したいこと
SearchViewに音声認識機能を追加し、
ToolbarにVoiceSearchButtonを追加したところ、
VoiceSearchButtonを長押ししたときのエフェクトが四角いです。
左側のxボタンと同じように丸くするにはどうしたらいいでしょうか。
###発生している問題・エラーメッセージ
マイクボタンを長押ししたときのエフェクトが四角い
左隣のxボタンは丸い
###該当のソースコード
activity_main.xml
activity_main.xml
1<?xml version="1.0" encoding="utf-8"?> 2<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent"> 6 <LinearLayout 7 android:orientation="vertical" 8 android:layout_width="match_parent" 9 android:layout_height="match_parent"> 10 <android.support.v7.widget.Toolbar 11 android:id="@+id/toolbar" 12 android:background="?attr/colorPrimary" 13 android:layout_width="match_parent" 14 android:layout_height="wrap_content" 15 app:theme="@style/ThemeOverlay.AppCompat.Dark" /> 16 <TextView 17 android:id="@+id/result" 18 android:textSize="20sp" 19 android:layout_margin="10dp" 20 android:textColor="#FF34" 21 android:layout_width="match_parent" 22 android:layout_height="match_parent" /> 23 </LinearLayout> 24</RelativeLayout>
styles.xml
styles.xml
1<resources> 2 3 <!-- Base application theme. --> 4 <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 5 <!-- Customize your theme here. --> 6 <item name="colorPrimary">@color/colorPrimary</item> 7 <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 8 <item name="colorAccent">@color/colorAccent</item> 9 </style> 10 11</resources>
AndroidManifest.xml
AndroidManifest.xml
1<?xml version="1.0" encoding="utf-8"?> 2<manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 package="jp.co.araiyusuke.myapplication"> 4 5 <application 6 android:allowBackup="true" 7 android:icon="@mipmap/ic_launcher" 8 android:label="@string/app_name" 9 android:supportsRtl="true" 10 android:theme="@style/AppTheme"> 11 <activity 12 android:name=".MainActivity" 13 android:launchMode="singleTop" 14 > 15 16 <intent-filter> 17 <action android:name="android.intent.action.MAIN" /> 18 <category android:name="android.intent.category.LAUNCHER" /> 19 </intent-filter> 20 21 <intent-filter> 22 <action android:name="android.intent.action.SEARCH" /> 23 </intent-filter> 24 25 <meta-data 26 android:name="android.app.default_searchable" 27 android:value=".MainActivity" /> 28 29 <meta-data 30 android:name="android.app.searchable" 31 android:resource="@xml/searchable" /> 32 </activity> 33 </application> 34</manifest>
res/xml/searchable.xml
res/xml/searchable.xml
1<?xml version="1.0" encoding="utf-8"?> 2<searchable 3 xmlns:android="http://schemas.android.com/apk/res/android" 4 android:label="@string/app_name" 5 android:hint="@string/hint" 6 android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" />
res/menu/menu_search.xml
res/menu/menu_search.xml
1<?xml version="1.0" encoding="utf-8"?> 2<menu xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto"> 4 <item 5 android:id="@+id/search_view" 6 android:title="@string/app_name" 7 app:actionViewClass="android.support.v7.widget.SearchView" 8 app:showAsAction="always" /> 9</menu>
strings.xml
strings.xml
1<resources> 2 <string name="app_name">My Application</string> 3 <string name="hint">住所</string> 4</resources>
MainActivity.java
MainActivity.java
1import android.app.SearchManager; 2import android.content.Context; 3import android.content.Intent; 4import android.os.Bundle; 5import android.support.v7.app.AppCompatActivity; 6import android.support.v7.widget.SearchView; 7import android.support.v7.widget.Toolbar; 8import android.util.Log; 9import android.view.Menu; 10import android.view.MenuInflater; 11import android.widget.TextView; 12 13public class MainActivity extends AppCompatActivity { 14 15 private SearchView mSearchView; 16 @Override 17 protected void onCreate(Bundle savedInstanceState) { 18 super.onCreate(savedInstanceState); 19 setContentView(R.layout.activity_main); 20 setToolbar(); 21 } 22 23 private void setToolbar() { 24 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 25 setSupportActionBar(toolbar); 26 } 27 28 @Override 29 public boolean onCreateOptionsMenu(Menu menu) { 30 MenuInflater inflater = getMenuInflater(); 31 inflater.inflate(R.menu.menu_search, menu); 32 mSearchView = (SearchView) menu.findItem(R.id.search_view).getActionView(); 33 mSearchView.setSubmitButtonEnabled(false); 34 35 mSearchView.setMaxWidth(Integer.MAX_VALUE); 36 SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); 37 mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); 38 mSearchView.findViewById(android.support.v7.appcompat.R.id.search_plate) 39 .setBackgroundColor(getResources().getColor(android.R.color.transparent)); 40 mSearchView.findViewById(android.support.v7.appcompat.R.id.submit_area) 41 .setBackgroundColor(getResources().getColor(android.R.color.transparent)); 42 43 44 mSearchView.setOnQueryTextListener(new android.support.v7.widget.SearchView.OnQueryTextListener() { 45 @Override 46 public boolean onQueryTextSubmit(String query) { 47 Log.d("onQueryTextSubmit", query); 48 return false; 49 } 50 51 @Override 52 public boolean onQueryTextChange(String query) { 53 Log.d("onQueryTextChange", query); 54 return false; 55 } 56 }); 57 58 boolean autofocus = false; 59 mSearchView.setIconified(!autofocus); 60 mSearchView.setIconifiedByDefault(true); 61 return true; 62 } 63 @Override 64 protected void onNewIntent(Intent intent) { 65 setIntent(intent); 66 if (Intent.ACTION_SEARCH.equals(intent.getAction())) { 67 String query = intent.getStringExtra(SearchManager.QUERY); 68 Log.d("onNewIntent", query); 69 boolean submit = false; 70 mSearchView.setQuery(query, submit); 71 TextView mResultTv = (TextView) findViewById(R.id.result); 72 mResultTv.setText(query); 73 } 74 } 75}
###試したこと
課題に対してアプローチしたことを記載してください
###補足情報(言語/FW/ツール等のバージョンなど)
Asus ZenFoneGo (Android 5.1.1)
あなたの回答
tips
プレビュー