【问题标题】:Material Button - Styles not being applied correctly, ugly as hell材质按钮 - 样式应用不正确,丑得要命
【发布时间】:2018-11-09 11:28:55
【问题描述】:

丑陋的结果:

我的布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                             xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
                                             android:layout_height="match_parent">
    <com.google.android.material.button.MaterialButton
            android:id="@+id/material_text_button"
            style="@style/Widget.MaterialComponents.Button.TextButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Contact"
            android:layout_marginTop="8dp"
            app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent"
            android:layout_marginStart="59dp"/>

    <com.google.android.material.button.MaterialButton
            android:id="@+id/material_button"
            style="@style/Widget.MaterialComponents.Button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Default"
            app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="114dp"
            android:layout_marginTop="109dp" app:layout_constraintTop_toBottomOf="@+id/material_text_button"/>


</android.support.constraint.ConstraintLayout>

颜色:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#008577</color>
    <color name="colorOnPrimary">#FFFFFF</color>
    <color name="colorPrimaryDark">#00574B</color>
    <color name="colorAccent">#D81B60</color>
    <color name="colorOnSurface">#000000</color>
    <color name="colorOnSurfaceSecondary">#d3d3d3</color>
    <color name="colorOnBackground">#000000</color>
</resources>

Gradle:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.android.material:material:1.0.0-beta01'
}

我在这里做错了什么?默认情况下真的要这么丑吗?这是在 API 21 上。

材料链接:https://material.io/develop/android/components/material-button/

【问题讨论】:

  • 您的按钮有错误。这是什么?
  • 你是说设计师身上的红色感叹号?这是因为其中一个不受 X 和 Y 约束,但不会影响按钮的外观。
  • 这不是它存在的原因。只是为了确认一下,我在 ConstraintLayout 中放置了一个 Button,甚至没有收到警告。
  • 这是默认行为,您可能在某些时候使用了“推断约束”,或者没有。 Android Studio 3.1 全新安装的行为就是这样。真的,这与问题无关。
  • 我从未在任何计算机或任何安装上遇到过有关 ConstraintLayouts 的警告或错误。只是为了检查,检查红色错误(点击设计视图右上角的感叹号)。

标签: android material-design


【解决方案1】:

事实证明,当我在模拟器上运行应用程序时,按钮的外观非常漂亮。意思是,我所做的并没有错。

Android Studio Preview 似乎在这里出错了,我只能想知道是否可以修复。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-23
    • 1970-01-01
    • 2015-08-01
    • 2016-07-13
    • 2016-01-11
    • 2018-02-05
    相关资源
    最近更新 更多