【问题标题】:drawableLeft/Right etc. doesn't work with Theme.MaterialComponentsdrawableLeft/Right 等不适用于 Theme.MaterialComponents
【发布时间】:2019-09-24 15:29:56
【问题描述】:

当我想使用 drawableLeft/Right 等带有按钮的 Activity Theme.MaterialComponents.... 时,它们不会显示。但是,如果我使用主题 Base.Theme.AppCompat,它们会按预期工作。 这是按钮:

       <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Test Button"
            android:drawableLeft="@drawable/ic_envelope"/>

这就是主题Base.Theme.MaterialComponents的外观

这是Base.Theme.AppCompat

如何使drawableLeftBase.Theme.MaterialComponents 主题一起使用?

【问题讨论】:

  • 使用com.google.android.material.button.MaterialButtonapp:iconGravityapp:icon
  • 谢谢,这行得通!

标签: android material-design android-button material-components-android material-components


【解决方案1】:

只需使用带有 app:icon 属性的MaterialButton

<com.google.android.material.button.MaterialButton
      style="@style/Widget.MaterialComponents.Button.OutlinedButton.Icon"
      app:icon="@drawable/ic_add_24px"
      ../> 

<com.google.android.material.button.MaterialButton
    style="@style/Widget.MaterialComponents.Button.Icon"
    app:icon="@drawable/ic_add_24px"
    ../>

<com.google.android.material.button.MaterialButton
    style="@style/Widget.MaterialComponents.Button.TextButton.Icon"
    app:icon="@drawable/ic_add_24px"
    ../>

使用app:iconGravity来配置start|end|textStart|textEnd

<com.google.android.material.button.MaterialButton
    app:iconGravity="end"
    ../>

【讨论】:

  • 看起来您对答案的新编辑已经覆盖了我之前对您的答案的编辑 - 您可以将这些编辑合并在一起吗?谢谢!
  • @Edric 他不能。如果您认为这些修改非常重要,则必须再次应用它们
  • @TimCastelijns 是的,我知道你不能合并编辑。最多可以回滚。
猜你喜欢
  • 2020-09-15
  • 2016-07-15
  • 1970-01-01
  • 2019-06-04
  • 2019-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多