我想删除在聚焦/键入时出现在文本下面的行(而不是android:id/search_plate
),但我无法删除它。
- 这可能吗?
- 如果可能的话,我该怎么做呢?
- 我应该读什么书来学习做这件事?
背景:
我们在谈论这个:
当然,我们在这里讨论的是自定义渲染。
我试过什么了?
SO Solution 1
SO Solution 2
我的程式码外观:
public class CustomSearchBarRenderer : SearchBarRenderer
{
public CustomSearchBarRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
{
base.OnElementChanged(e);
SearchView searchView = Control;
searchView.SetInputType(InputTypes.ClassText | InputTypes.TextVariationNormal);
int textViewId = searchView.Context.Resources.GetIdentifier("android:id/search_src_text", null, null);
EditText textView = (searchView.FindViewById(textViewId) as EditText);
textView.SetBackgroundColor(G.Color.ParseColor("#FFFFFF"));
textView.SetTextColor(G.Color.ParseColor("#191E24"));
textView.SetHintTextColor(G.Color.ParseColor("#191E24"));
textView.SetTextSize(Android.Util.ComplexUnitType.Dip, 16);
textView.SetPadding(8, 0, 40, 0);
int searchIconId = Context.Resources.GetIdentifier("android:id/search_mag_icon", null, null);
ImageView searchViewIcon = searchView.FindViewById<ImageView>(searchIconId);
searchViewIcon.SetImageDrawable(null);
int searchCloseIconId = Context.Resources.GetIdentifier("android:id/search_close_btn", null, null);
ImageView searchClose = searchView.FindViewById<ImageView>(searchCloseIconId);
searchClose.SetPadding(8, 0, 8, 0);
searchView.Iconified = false;
searchView.SetIconifiedByDefault(false);
//new code, did not work
//this.Control.SetInputType(InputTypes.Null);
//new code, did not work
//GradientDrawable gd = new GradientDrawable();
//gd.SetColor(Android.Graphics.Color.Transparent);
//this.Control.SetBackground(gd);
//new code, did not work
//var plateId = Resources.GetIdentifier("android:id/search_plate", null, null);
//var plate = Control.FindViewById(plateId);
//plate.SetBackgroundColor(Android.Graphics.Color.Green);
//new code, did not work
//LinearLayout linearLayout = this.Control.GetChildAt(0) as LinearLayout;
//linearLayout = linearLayout.GetChildAt(2) as LinearLayout;
//linearLayout = linearLayout.GetChildAt(1) as LinearLayout;
//linearLayout.Background = null; //removes underline
}
}
1条答案
按热度按时间44u64gxh1#
该文本下划线与键盘建议有关
由于某些原因,标志
TextFlagNoSuggestions
单独不起作用,需要与TextVariationVisiblePassword
结合使用。