首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >动态创建元素

动态创建元素
EN

Stack Overflow用户
提问于 2017-05-22 11:22:09
回答 1查看 986关注 0票数 0

我正在做一个项目,在这个项目中,我必须创建一个搜索菜单来查找特定的文件,但是我需要创建一个搜索菜单,因为每个部分都有不同的搜索字段,我的问题是:如何通过活动上的代码创建EditTexts、旋转器等等?

EN

回答 1

Stack Overflow用户

发布于 2017-05-22 12:08:06

代码语言:javascript
运行
复制
    //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”等内容。

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

https://stackoverflow.com/questions/44111588

复制
相关文章

相似问题

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