【问题标题】:Using material design, how to programmatically create a Material Button?使用材料设计,如何以编程方式创建材料按钮?
【发布时间】:2019-04-10 13:48:08
【问题描述】:

我知道如何以编程方式创建普通按钮和文本视图。但是,材料设计组件的文档有点缺乏。如何动态创建 Material Button(和其他 Material Design 组件)?

指的是官方文档here,但它只显示了xml创建。似乎它应该相当简单,但我在 google/stackoverflow 上没有找到任何关于此的内容。

【问题讨论】:

标签: android material-design material-ui


【解决方案1】:

您需要添加适当的依赖项。检查此link 然后您可以将其创建为平均视图。

【讨论】:

  • 嗨 Arthur,我已经添加了依赖项,我想我不确定的是,我是否只需按如下方式创建 MaterialButton:MaterialButton myButton = new MaterialButton(this)
  • 是的。如果您需要以某种方式自定义它,只需使用带有 xml 属性名称的 setter,例如 button.setText("Some text");
猜你喜欢
  • 1970-01-01
  • 2016-05-09
  • 1970-01-01
  • 2015-09-07
  • 2021-09-14
  • 2020-04-14
  • 2016-06-28
  • 2015-01-04
  • 2016-09-20
相关资源
最近更新 更多