小编Dar*_*ony的帖子

Android 33 - Android Studio 中的清单和布局文件中的问题

目前在我的 Android 应用程序中,targetSdkVersion 32在我的 AndroidManifest.xml 文件中,我有:

<application
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_nameshort"
    android:supportsRtl="false"
    android:theme="@style/AppTheme">
    
    <activity android:name=".MainActivity"
        android:screenOrientation="portrait"
        tools:ignore="LockedOrientationActivity"
        android:windowSoftInputMode="adjustPan"
        android:exported="true">
Run Code Online (Sandbox Code Playgroud)

一切都很好并且运行良好。

然而现在当我更新我的应用程序时,Android Studio (Chipmunk | 2021.2.1) 建议使用targetSdkVersion 33. 执行此操作后,AndroidManifest.xml 中存在问题:

unknown attribute android:supportsRtl
unknown attribute android:screenOrientation
unknown attribute android:windowSoftInputMode 
Run Code Online (Sandbox Code Playgroud)

以及 XML 布局文件中的多个问题。例如:

unknown android:contentDescription
unknown android:layout_toEndOf
Run Code Online (Sandbox Code Playgroud)

以及更多...

我已经尝试过使缓存无效,重建项目,但没有任何帮助。只有切换回目标版本 32 才有帮助。这些属性真的已被弃用还是有任何问题?它并没有说已弃用,只是说未知。

我还从缓存文件夹中物理删除了文件,还重新安装了 API 33 SDK,但没有任何帮助。

我什至重新安装了 Android Studio,但没有成功。API 33 与 Android Studio 似乎有问题。

android android-manifest

34
推荐指数
3
解决办法
1万
查看次数

Android ResourcesNotFoundException 但是图像存在于所有可绘制文件夹中

一位 Android 用户在 Nexus 5X 设备上发生了崩溃,并报告如下:

Fatal Exception: java.lang.RuntimeException
Unable to start activity ComponentInfo{package.MainActivity}: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class ImageView
android.app.ActivityThread.performLaunchActivity
Caused by android.view.InflateException
Binary XML file line #8: Binary XML file line #8: Error inflating class ImageView
Caused by android.view.InflateException
Binary XML file line #8: Error inflating class ImageView

Caused by android.content.res.Resources$NotFoundException
Drawable (missing name) with resource ID #0x7f0700b8

Caused by android.content.res.Resources$NotFoundException
Unable to find resource ID #0x7f0700b8
Run Code Online (Sandbox Code Playgroud)

指向Mainactivity中的第61行:MainActivity.onCreate(MainActivity.java:61),也就是这一行:

 this.setContentView(R.layout.activity_main); …
Run Code Online (Sandbox Code Playgroud)

android android-resources

16
推荐指数
0
解决办法
1421
查看次数

Github 解决冲突总是将基础分支合并到我当前的分支

我在 PHP Storm 的本地分支机构工作。任务完成后,我提交我的分支并推送到 git。

在 Github 页面上,我创建了一个 Pull 请求 DEV <- 我的分支。Dev 是基础分支,我将把我的分支合并到其中。

到目前为止这还可以。但如果某些文件存在冲突 - 根据本文https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/resolving- github 上的合并冲突

就我而言,相同的文件已在其他分支中更新并之前合并到 DEV 中。现在在我的分支中有相同的文件和其他更改。

当我解决冲突(甚至可以是一行)时,我将其标记为已解决并提交合并。

现在,整个 DEV 基础分支被合并到我自己的分支中,这不太好。

因为我正在将我的分支合并到 DEV,而不是相反。如何才能避免这种情况呢?

我尝试重新创建相同的分支,但是一旦开发合并到这里,它就始终存在。每次冲突都会发生这种情况,这是无稽之谈 - 正如上述网络的第 8 点所说:

解决所有合并冲突后,单击提交合并。这会将整个基础分支合并到您的头分支中。

在此输入图像描述

merge github merge-conflict-resolution

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

Android - getResources().getIdentifier 替换

在 android 中,我循环遍历数据库并分配文本和图像:

Cursor res = myDb.getAllData();

while (res.moveToNext()) {
    Actors actor = new Actors();
    actor.setName(res.getString(1));

    String th =  res.getString(11);
    Integer thumb = this.getResources().getIdentifier(th, "drawable", "mypackage");

    actor.setThumb(R.drawable.th);
}
Run Code Online (Sandbox Code Playgroud)

然而,Lint 建议不要使用 getIdentifier - 不鼓励使用此函数,因为资源反射会使执行代码的构建优化和编译时验证变得更加困难。

在数据库列中,我只有图像名称(字符串)。如何替换 getIdentifier?

即使我将 DB 列直接更改为R.drawable.imagename,它仍然是一个字符串,因为setThumb我需要一个可绘制对象。

android

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

Android 意图选择器 - 导航应用

在我的应用程序中,我有一个按钮,可以打开带有发送坐标的 Google 地图。

 final ImageView view = findViewById(R.id.navigate);
        view.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
                        Uri.parse("http://maps.google.com/maps?daddr="+gps1+","+gps2));
                startActivity(intent);
            }
        });
Run Code Online (Sandbox Code Playgroud)

这工作正常,但我想在单击按钮后向用户提供他设备中的所有导航应用程序。

所以不是自动打开谷歌地图,而是让用户选择使用哪个应用程序。

我找到了这个解决方案,但这仅适用于 Google 地图和 Waze。由于我不知道用户的设备上有哪些导航应用程序以及多少导航应用程序,因此我无法对所有现有的导航应用程序进行硬编码。

String url = "waze://?ll=" + latitude + ", " + longitude + "&navigate=yes";
Intent intentWaze.setPackage("com.waze");
Intent intentWaze = new Intent(Intent.ACTION_VIEW, Uri.parse(url));

String uriGoogle = "google.navigation:q=" + latitude + "," + longitude;
Intent intentGoogleNav.setPackage("com.google.android.apps.maps");
Intent intentGoogleNav = new Intent(Intent.ACTION_VIEW, Uri.parse(uriGoogle));

String title = context.getString(R.string.title);
Intent chooserIntent = …
Run Code Online (Sandbox Code Playgroud)

android android-intent

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

Cypress 10 配置文件与 Cucumber

在我将 Cypress 迁移到版本 10 后,Cucumber 预处理器停止工作。我找到了一些实现的解决方案,并且还安装了最新的@badeball/cypress-cucumber-preprocessor。

现在我不知道如何设置 cypress.config.js 文件,因为原始的插件文件夹已被弃用。

在插件文件夹下的旧 index.js 中,我有:

const cucumber = require("cypress-cucumber-preprocessor").default;

module.exports = (on, config) => {
  // `on` is used to hook into various events Cypress emits
  // `config` is the resolved Cypress config
  on("file:preprocessor", cucumber());
...
Run Code Online (Sandbox Code Playgroud)

现在插件设置应该位于 cypress-config.js 中:

 e2e: {
    baseUrl: 'http://localhost:4200',
    specPattern: 'cypress/e2e/features',
    setupNodeEvents(on, config) {

const addCucumberPreprocessorPlugin =
  require('@badeball/cypress-cucumber-preprocessor').addCucumberPreprocessorPlugin;

      on('file:preprocessor',   addCucumberPreprocessorPlugin(on, config));
    }

  },
Run Code Online (Sandbox Code Playgroud)

但现在我有一个错误,因为on('file:preprocessor', addCucumberPreprocessorPlugin());addCucumberPreprocessorPlugin 不是一个函数。我知道不是,但是如何为黄瓜正确配置此部分?我没有找到任何有关此的信息。

如果我只是删除on('file:preprocessor', addCucumberPreprocessorPlugin(on, config));,在执行功能测试文件后,会出现以下错误:

您可能需要适当的加载程序来处理此文件类型,当前没有配置加载程序来处理此文件

cypress cypress-cucumber-preprocessor

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

当设备字体大小发生变化时,Android 不会增加应用程序中的文本

我有一个 Android 应用程序,在其中使用项目列表,例如左侧有一个缩略图,右侧有一些文本。

一切正常,但我注意到一个问题,当用户增加其设备的字体大小时(不是在应用程序中,但通常对于他的设备,因为他是老年人,需要更大的字母)。由于每个移动设备都可以在设置中更改字体大小 - 小。中型、大型、非常大等)

但是,此更改还增加了我的应用程序中的字体大小,然后项目列表看起来非常糟糕,因为图像右侧的文本变为多行,或者即使停留在一行上,缩放后看起来也很糟糕,因为设备文本大小增加了。

通常我使用 SP 中的文本大小(例如 16sp):

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="16sp"
</TextView>
Run Code Online (Sandbox Code Playgroud)

有没有办法让我的应用程序不受设备字体大小设置的影响,因为我的应用程序有自己的字体大小或者没有什么可做的?

现在,如果有人需要在他的设备上使用大字体,他就无法正常使用该应用程序。

android font-size

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

丝柏 + 黄瓜 - 相同的步骤定义

假设我有Feature1.feature 和Feature2.feature 文件。首先我有步骤:

Scenario: Test scenario1
Given   I Open the app
When    I Click on Tab1
Run Code Online (Sandbox Code Playgroud)

在第二个文件中我有:

Scenario: Test scenario2
Given   I Open the app
When    I Click on Tab2
Run Code Online (Sandbox Code Playgroud)

在step1.js文件的step_definitions文件夹下:

Given("I open the app", () => {
  cy.visit("/home");
});

When("I Click on Tab1", () => {
  cy.get('[title="Tab1"]'.click();
});
Run Code Online (Sandbox Code Playgroud)

在step_definitions文件夹下,我们有多个js文件(由每个测试用例分隔)。那么对于第二种情况,在step2.js中我是否需要再次定义“打开应用程序”步骤?:

Given("I open the app", () => {
  cy.visit("/home");
});
Run Code Online (Sandbox Code Playgroud)

或者它在steps_definition下的所有文件中进行全局查找?那么我只需要从以下开始:

When("I Click on Tab2", () => {
  cy.get('[title="Tab2"]'.click();
});
Run Code Online (Sandbox Code Playgroud)

但是,如果多个用户正在处理测试用例并且他们不小心在不同的文件中定义了相同的步骤,例如

在一个文件中

Given("I open the app", () => {
  cy.visit("/home");
}); …
Run Code Online (Sandbox Code Playgroud)

cypress-cucumber-preprocessor

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

Android 已弃用 Tasks.call - 替换

在我的 Android 应用程序中,我可以选择将数据库备份到 Google Drive。为此,我正在使用 DriveServiceHelper 类,但我刚刚注意到,在 Android 11 中,Task.call 已被弃用。

      public Task<FileList> queryFiles() {
    return Tasks.call(mExecutor, () ->
            mDriveService.files().list().setSpaces("drive").execute());
}
Run Code Online (Sandbox Code Playgroud)

从我的 BackupActivity 然后我queryFilesbackup方法调用:

  public void backup(View v) {
        driveServiceHelper.queryFiles()
                .addOnSuccessListener(fileList -> {
                  // another code
                })
                .addOnFailureListener(e -> showMsgSnack(getString(R.string.uploaderror)));
Run Code Online (Sandbox Code Playgroud)

我没有找到任何解决方案来处理这个问题以避免该类的完全返工。

我尝试过的:

我尝试替换为可运行的,也可调用的,但它不起作用,因为预期返回任务,而不是文件列表。

我也尝试使用TaskCompletionSource

public Task<FileList> queryFiles(int delay) throws IOException, ExecutionException, InterruptedException {

    new Thread(
            new Runnable() {

                @Override
                public void run() {
                    TaskCompletionSource<FileList> taskCompletionSource = new TaskCompletionSource<>();

                    FileList result = null;
                    try { …
Run Code Online (Sandbox Code Playgroud)

android android-asynctask google-drive-api

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

赛普拉斯选择下拉列表中的最后一个选项

我有一个动态生成的下拉列表,其正常结构如下:

<select>
<option value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
etc.
</select>
Run Code Online (Sandbox Code Playgroud)

这是一种分页,我不知道表中有多少项目,也不想根据项目计数计算下拉列表中有多少个选项。

我想通过 Cypress 实现的目标就是始终选择最后一个选项。

我知道我可以按名称或值选择任何选项,例如cy.get('select').select('10')

还有索引:cy.get('select').select(0)

但我不知道最后一个索引。

我也尝试过select().last(),但这不起作用,因为select不能为空。

select dynamic-content cypress

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

如何检查多维数组键是否在数组中不止一次?

我有这个多数组:

Array ( 
    [0] => Array ( 
            [title] => f2 
        ) 
    [1] => Array ( 
            [title] => f2 
        ) 
    [2] => Array ( 
            [title] => f3 
        ) 
) 
Run Code Online (Sandbox Code Playgroud)

我只想检查键(由表示$item)是否在数组中不止一次,因此在我的情况下,“ f2”在数组中不止一次。

我使用进行了尝试in_array,但不适用于多数组。

然后我尝试了这个:

$item='f2';
$array_count = array_count_values($titles);
if (array_key_exists($item, $array_count) && ($array_count[$item] > 1))
{
    echo 'more than once';

}
Run Code Online (Sandbox Code Playgroud)

但这仍然无法正常工作。

php arrays

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

一行PHP多个比较条件

我有一个字符串的定义:

$string = $string1 .' / '.$string2.' / '.$string3;
Run Code Online (Sandbox Code Playgroud)

如果所有字符串不存在,是否可以在一行条件中写入它们,写“0”?

if (!string1) {$string1="0";}
if (!string2) {$string2="0";}
if (!string3) {$string3="0";}
Run Code Online (Sandbox Code Playgroud)

我试过类似的东西:

$string = !$string1 ? "0" : $string1.' / '.!$string2 ? "0" : $string2.' / '.!$string3 ? "0": $string3;
Run Code Online (Sandbox Code Playgroud)

但这样就行不通了。

我也试过??:

$string = $string1 ?? "0" .' / '.$string2 ?? "0" .' / '.$string3 ?? "0";
Run Code Online (Sandbox Code Playgroud)

php comparison-operators

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