java - Android开发中的Button和Androidx.appcompat.widget.AppCompatButton有什么区别?

标签 java android kotlin

我正在尝试在最新的 Android Studio 北极中创建一个注册页面。因此,我尝试使用 Button Class 自定义和设置按钮样式,但在使用 AppCompatButton 之前没有进行任何可观察到的更改,并且按钮的所有样式和自定义都已实现。我想详细说明这两个 View 以及为什么我不能使用 Button Class 进行更改。谢谢。
这些是 AppCompatButton 和 Button 的代码

<androidx.appcompat.widget.AppCompatButton
                android:id="@+id/sign_up_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:background="@drawable/button_border_signin"
                android:elevation="0dp"
                android:text="Sign Up"
                android:textColor="#e0e0e0e0"
                android:textStyle="bold" />
按钮
<Button
                android:id="@+id/sign_up_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:background="@drawable/button_border_signin"
                android:elevation="0dp"
                android:text="Sign Up"
                android:textColor="#e0e0e0e0"
                android:textStyle="bold" />

最佳答案

可能原因
您可能在后台可绘制文件中使用了一些与旧版本不兼容的功能。

Button 和 AppCompatButton 的区别
AppCompatButton 只是一个 Button它支持旧版本平台上的兼容功能,包括:

  • 允许通过 ViewCompat 中的背景着色方法对其背景进行动态着色.
  • 允许使用 R.attr.backgroundTint 设置背景色调和 R.attr.backgroundTintMode .
  • 允许使用 R.attr.fontFamily 设置字体系列

  • 当您在布局中使用 Button 并且顶级 Activity/对话框由 appcompat 提供时,这将自动使用。您应该只需要在编写自定义 View 时手动使用此类。
    来源: AppCompatButton

    关于java - Android开发中的Button和Androidx.appcompat.widget.AppCompatButton有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69283849/

    相关文章:

    kotlin - kotlin,在subscribe()中使用观察者对象实例时得到了 “Type mismatch. Required: Disposable? Found: Unit”

    java - 如何解决 IllegalStateException : Failed to load ApplicationContext

    java - 编译项目中包含哪些 Maven 依赖范围?

    java - 为什么这被认为是不安全的?

    android - 为什么要使用 GoogleAPIClient 来请求位置更新?

    android - 开始新 Activity 时使用 Glide

    java - 来自 Java 的 Kotlin null

    java - android 通知 - RemoteServiceException

    android - 推送通知能否与 UI 线程并行执行代码?

    Kotlin 启动与启动(Dispatchers.Default)