删除SearchView搜索语音按钮行

时间:2015-04-01 13:54:21

标签: android searchview

感谢关于SearchView自定义的其他SO相关帖子,我能够自定义SearchView到这一点:

enter image description here

现在我正在尝试添加语音搜索,我可以更改语音按钮后台资源:

int searchVoiceIconId = searchPlate.getContext().getResources().getIdentifier("android:id/search_voice_btn", null, null);
ImageView searchVoiceIcon = (ImageView) searchView.findViewById(searchVoiceIconId);
searchVoiceIcon.setImageResource(R.drawable.ic_action_mic);
searchVoiceIcon.setBackgroundColor(Color.TRANSPARENT);

但是,我似乎无法摆脱语音搜索按钮下的行。

enter image description here

任何建议????

由于

3 个答案:

答案 0 :(得分:2)

这是一个迟到的回复,但它可能对将来有所帮助。

添加以下行:

<style name="AppTheme.SearchView" parent="Widget.AppCompat.SearchView">
    <!-- Gets rid of the "underline" in the mic button-->
    <item name="submitBackground">@null</item>

到您的values / styles.xml文件,它将删除该行。

答案 1 :(得分:1)

代码:

((LinearLayout)search.findViewById(R.id.search_voice_btn).getParent()).setBackgroundColor(Color.TRANSPARENT);

答案 2 :(得分:0)

int submitAreaId = searchView.getContext().getResources()
                .getIdentifier("android:id/submit_area", null, null);
View submitAreaView = searchView.findViewById(submitAreaId);
if (submitAreaView != null) {
    submitAreaView.setBackgroundColor(Color.parseColor("#00000000"));
}

这应该删除非文本输入区域的任何下划线。

相关问题