首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Xamarin表单中自定义AutoCompleteTextView

问如何在Xamarin表单中自定义AutoCompleteTextView
EN

Stack Overflow用户
提问于 2019-05-07 18:38:29
回答 1查看 128关注 0票数 0

我正在尝试定制AutoCompleteTextView的外观,我需要一个四舍五入的条目

到目前为止,我已经尝试过了

代码语言:javascript
复制
 [assembly: ExportRenderer(typeof(AutoCompleteViewv3), 
 typeof(AutoCompleteViewRendererv3))]
namespace PredictiveList.Droid
{
 public class AutoCompleteViewRendererv3  : ViewRenderer<AutoCompleteViewv3, 
  AutoCompleteTextView>
{
    static string[] COUNTRIES = new string[] {
  "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra",
  "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", };

    public AutoCompleteViewRendererv3(Android.Content.Context context) : base(context)
    {

    }

    protected override void OnElementChanged(ElementChangedEventArgs<AutoCompleteViewv3> e)
    {
        base.OnElementChanged(e);

        if (e.OldElement != null || this.Element == null)
            return;

        // var textInputLayout = (TextInputLayout)LayoutInflater.From(Context).Inflate(Resource.Layout.TextInputLayout, null);

        var autoComplete = new AutoCompleteTextView(Context);
        autoComplete.SetBackgroundResource(Resource.Drawable.rounded_cornersrev);


        //var autoCompleteTextView = (AutoCompleteTextView)LayoutInflater.From(Context).Inflate(Resource.Layout.TextInputLayout, null);
        //var  txtSearch = (AutoCompleteTextView)FindViewById(Resource.Id.autocomplete_country);
        // TextView name = (TextView)Android.Views.View.FindViewById(Resource.Id.txt_searchhh);
        AutoCompleteTextView textView = new AutoCompleteTextView(Context);
        textView = FindViewById<AutoCompleteTextView>(Resource.Id.autocomplete_country);
        var adapter = new ArrayAdapter<String>(Context, Resource.Layout.list_item, COUNTRIES);
        autoComplete.Adapter = adapter;
        SetNativeControl(autoComplete);
    }

    // Use the control here.
    protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        base.OnElementPropertyChanged(sender, e);

        if (this.Element == null || this.Control == null)
            return;

        // variable this.Control is the AutoCompleteTextView, so you an manipulate it.
    }
}

}

我正在尝试以Xamarin的形式实现这一点,如果有人有其他想法,请建议

​

​

另外,请帮助我如何删除条目的下划线

EN

回答 1

Stack Overflow用户

发布于 2019-05-08 15:06:46

试一下这个方法:

代码语言:javascript
复制
AutoCompleteTextView textView = new AutoCompleteTextView(textView =FindViewById<AutoCompleteTextView>(Resource.Id.autocomplete_country);

textView.Background = null; // Set background be null

​

​

​

​

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56020728

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档