小编Lud*_*g W的帖子

即使在高 API 级别设备上,Androidx AppCompatButton 看起来也与 Button 不同

根据文档

支持旧版本平台上兼容功能的按钮,包括:

允许通过 ViewCompat 中的背景色调方法对其背景进行动态色调。允许使用 R.attr.backgroundTint 和 R.attr.backgroundTintMode 设置背景色调。当您在布局中使用 Button 并且顶级活动/对话框由 appcompat 提供时,这将自动使用。您应该只需要在编写自定义视图时手动使用此类。

现在,这让我假设以下两个按钮在高级设备上看起来完全相同。

<androidx.appcompat.widget.AppCompatButton
        android:text="AppCompatButton"
        android:id="@+id/appcompatbutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

<Button
        android:layout_below="@id/appcompatbutton"
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:text="Button"
        android:layout_height="wrap_content" />
Run Code Online (Sandbox Code Playgroud)

然而,这是它的实际外观:

在此处输入图片说明

我在以下模拟器上运行了这个:Galaxy Nexus,API:28 (720 x 1280 xhdpi)

当我像这样在 appTheme 中应用 buttonStyle 时:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="buttonStyle">@style/Widget.MaterialComponents.Button</item>
</style>
Run Code Online (Sandbox Code Playgroud)

它改变了 AppCompatButton 而不是像这样的普通按钮:(注意圆角边缘的细微差别)

在此处输入图片说明

我还尝试创建一个既继承自 android.widget.Button 又继承自 androidx.appcompat.widget.AppCompatButton 的自定义按钮,这两个按钮显示的行为与在 xml 中使用 AppCompatButton 的行为相同。所以感觉唯一的异常值是 XML 中的 Button。

问题 1: …

android android-button material-design material-components-android androidx

10
推荐指数
1
解决办法
3923
查看次数

Java正则表达式与预期不匹配

我最近在Java中使用正则表达式,我无法解决这个问题.

        Pattern p = Pattern.compile("[^A-Z]+");
        Matcher matcher = p.matcher("GETs");
        if (matcher.matches()) {
            System.out.println("Matched.");
        } else {
            System.out.println("Did not match.");
        }
Run Code Online (Sandbox Code Playgroud)

结果:未匹配(意外结果)说明这一点

我得到输出"不匹配." 这对我来说很奇怪,在阅读https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html时,我正在使用X +,它匹配"一个或多个倍".

我以为我的代码用语言会是这样的:

"检查字符串"GETs"中是否有一个或多个不属于A到Z的字符."

所以我期待以下结果:

"是的,在"GETs"中有一个不属于AZ的角色,正则表达式是一场比赛."

然而事实并非如此,我很困惑为什么会这样.我尝试了以下方法:

        Pattern p = Pattern.compile("[A-Z]+");
        Matcher matcher = p.matcher("GETs");
        if (matcher.matches()) {
            System.out.println("Matched.");
        } else {
            System.out.println("Did not match.");
        }
Run Code Online (Sandbox Code Playgroud)

结果:不匹配.(预期结果)

        Pattern p = Pattern.compile("[A-Z]+");
        Matcher matcher = p.matcher("GET");
        if (matcher.matches()) {
            System.out.println("Matched.");
        } else {
            System.out.println("Did not match.");
        }
Run Code Online (Sandbox Code Playgroud)

结果:匹配.(预期结果)

请解释为什么我的第一个例子不起作用.

java regex

1
推荐指数
1
解决办法
2407
查看次数