微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在使用 Gluon 客户端插件构建的 Android 应用程序中,PasswordField 'bullets' 未正确显示

如何解决在使用 Gluon 客户端插件构建的 Android 应用程序中,PasswordField 'bullets' 未正确显示

我正在使用来自 gluon client samplesHelloFx 项目。并使用 Java 11.0.10gluon client plugin 0.1.41 构建 APK。

添加认的 javafx TextField(javafx.scene.control.TextField) 和 PasswordField(javafx.scene.control.PasswordField)。

当我直接在桌面 (linux) 中运行该应用程序时,我能够在密码字段中输入内容并且“项目符号”正确显示

hellofx-password-field-bullets issue

但是当我构建 APK 并在 android 设备中进行测试时,项目符号未正确呈现,它们显示为框。

enter image description here

因此,我创建了一个新皮肤,将密码字段的“掩码字符”更改为 \u2022,如此 stackoverflow answer 所示。在桌面上,它没有问题。在 android 设备中,字符正确显示为项目符号,但是当我点击该字段时,键盘要么不显示,要么隐藏(如果它已经显示)。

这是PasswordFieldSkin.java

public class PasswordFieldSkin extends TextFieldSkin {
    public static final char BULLET = '\u2022';

    public PasswordFieldSkin(PasswordField passwordField) {
        super(passwordField);
    }

    @Override
    protected String maskText(String txt) {
        TextField field = getSkinnable();
        int n = field.getLength();
        StringBuilder passwordBuilder = new StringBuilder(n);

        for (int i = 0; i < n; i++) {
            passwordBuilder.append(BULLET);
        }

        return passwordBuilder.toString();
    }
}

这是 pom.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>hellofx</groupId>
    <artifactId>hellofx</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>HelloFX</name>

    <properties>
        <main.class>hellofx.HelloFX</main.class>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.release>11</maven.compiler.release>
        <javafx.version>15.0.1</javafx.version>
        <javafx.maven.plugin.version>0.0.6</javafx.maven.plugin.version>
        <client.maven.plugin.version>0.1.41</client.maven.plugin.version>
        <charm.version>6.0.6</charm.version>
        <glisten.afterburner.version>2.0.5</glisten.afterburner.version>
        <attach.version>4.0.10</attach.version>
        <connect.version>2.0.1</connect.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>${javafx.version}</version>
        </dependency>

        <!-- Added jackson dependency here -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.11.1</version>
        </dependency>
        <!-- Added JavaTime data type -->
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
            <version>2.12.2</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
            </plugin>

            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>${javafx.maven.plugin.version}</version>
                <configuration>
                    <mainClass>${main.class}</mainClass>
                </configuration>
            </plugin>

            <plugin>
                <groupId>com.gluonhq</groupId>
                <artifactId>client-maven-plugin</artifactId>
                <version>${client.maven.plugin.version}</version>
                <configuration>
                     <target>${client.target}</target>
                     <mainClass>${main.class}</mainClass>
                     <reflectionList>
                        <list>hellofx.Person</list>
                        <list>com.fasterxml.jackson.core.JsonFactory</list>
                     </reflectionList>
                     <nativeImageArgs>
                        <nativeImageArg>--allow-incomplete-classpath</nativeImageArg>
                     </nativeImageArgs>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>desktop</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <client.target>host</client.target>
            </properties>
        </profile>
        <profile>
            <id>ios</id>
            <properties>
                <client.target>ios</client.target>
            </properties>
        </profile>
        <profile>
            <id>android</id>
            <properties>
                <client.target>android</client.target>
            </properties>
        </profile>
    </profiles>

</project>

最后,这是主要方法

public class HelloFX extends Application {

    private Label parseStatusLabel = new Label("");
    
    private String serializedString = null;

    public void start(Stage stage) {
        String javaVersion = System.getProperty("java.version");
        String javafxVersion = System.getProperty("javafx.version");
        Label label = new Label("Hello,JavaFX " + javafxVersion + ",running on Java " + javaVersion + ".");

        ImageView imageView = new ImageView(new Image(HelloFX.class.getResourceAsstream("/hellofx/openduke.png")));
        imageView.setFitHeight(200);
        imageView.setPreserveRatio(true);

        TextField textField = new TextField();
        textField.setText("Username");
        PasswordField passwordField = new PasswordField();
        passwordField.setSkin(new PasswordFieldSkin(passwordField));
        passwordField.setText("Password");

        VBox root = new VBox(30,imageView,label,textField,passwordField,parseStatusLabel);
        root.setAlignment(Pos.CENTER);
        Scene scene = new Scene(root,640,480);
        scene.getStylesheets().add(HelloFX.class.getResource("styles.css").toExternalForm());
        stage.setScene(scene);
        stage.show();
    }
    
    public static void main(String[] args) {
        launch(args);
    }
}

如何解决这个问题?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。