我正在尝试在最新的 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它支持旧版本平台上的兼容功能,包括:
当您在布局中使用 Button 并且顶级 Activity/对话框由 appcompat 提供时,这将自动使用。您应该只需要在编写自定义 View 时手动使用此类。
来源: AppCompatButton
关于java - Android开发中的Button和Androidx.appcompat.widget.AppCompatButton有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69283849/