1

这个活动最初是有效的,但后来它突然停止工作,它向我显示了这个错误。我不知道如何解决它,我不记得从我的 app.gradle 文件中删除任何内容,但有人知道如何解决它吗?任何帮助将不胜感激

下面是我的密码视图主要活动(下面显示的 XML 有错误)''' PasscodeView PasswordView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_password_view);

    PasswordView = findViewById(R.id.PasswordView);
    PasswordView.setPasscodeLength(4)
            .setLocalPasscode("1234")
            .setListener(new PasscodeView.PasscodeViewListener() {
                @Override
                public void onFail() {
                    Toast.makeText(PasswordView.this, "Passcode do not match",Toast.LENGTH_SHORT).show();
                }
                @Override
                public void onSuccess(String number) {
                    Intent intent = new Intent(PasswordView.this,Main2Activity.class);
                    startActivity(intent);
                }
            });

}}

'''

密码视图的错误和 XML 屏幕截图

App.Gradle 的第一部分

App.Gradle 的第二部分(依赖项)

4

3 回答 3

8

添加androidx.legacy:legacy-support-v4:1.0.0项目依赖项部分。

//app/build.gradle dependencies section

dependencies {

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    // Other dependencies
}

更多细节:AndroidX 类映射AndroidX 工件映射

于 2020-07-02T07:43:05.517 回答
2

在您的布局文件中,将出现的 androidx.legacy.widget.Space 替换为 View。

例如。

 <androidx.legacy.widget.Space
       android:layout_width="8dp"
       android:layout_height="1dp" />

现在应该是

 <View
      android:layout_width="8dp"
      android:layout_height="1dp" />

更新我的 Gradle 版本后遇到了同样的问题。

于 2020-08-06T09:55:21.603 回答
0

而不是androidx.legacy.widget.Space你可以只使用android.widget.Space. 例如。:

<android.widget.Space
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:minHeight="1dp"/>
于 2021-02-25T13:08:48.260 回答