我正在做一个项目,在这个项目中,我必须创建一个搜索菜单来查找特定的文件,但是我需要创建一个搜索菜单,因为每个部分都有不同的搜索字段,我的问题是:如何通过活动上的代码创建EditTexts、旋转器等等?
发布于 2017-05-22 12:08:06
//create "reference to your layout"
LinearLayout yourFormLayout = FindViewById<LinearLayout(Resource.Id.Linear_MS);
//create container for parameters
var parameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
//add some parameters
param.SetMargins(20, 20, 20, 10);
//create new element
Button button = new Button(this);
button.Text = "click me";
button.SetBackgroundColor(Android.Graphics.Color.Black);
button.SetTextColor(Android.Graphics.Color.White);
button.LayoutParameters = parameters;
//add some events to your element
button.Click += (sender, e) => DoStuff();
//Add the button
yourFormLayout.AddView(button);AddView将元素作为子元素添加到最近的父级,因此如果您想要更柔和的位置,就必须阅读“GetDeclaredField”等内容。
https://stackoverflow.com/questions/44111588
复制相似问题