标签: androidx

androidStudio 中出现“包 android.support.v7.app 不存在”错误

我刚刚开始使用 androidStudio 进行 android 开发 我正在关注 udacity 教程,他们要求我们复制粘贴一些代码并运行它 我粘贴后无法运行 cod 我认为主要问题是在导入时

import android.support.v7.app.AppCompatActivity;

我已经在互联网上检查了这个问题的解决方案,包括stackoverflow,但似乎对于我尝试导入的每种情况都是不同的, import androidx.appcompat.app.AppcompatActivity;import android.support.v7.app.AppCompatActivity; 它并没有帮助我使用 androidStudio 版本 3.4

主要活动:

package com.example.android.justjava;

/**
 * IMPORTANT: Make sure you are using the correct package name.
 * This example uses the package name:
 * package com.example.android.justjava
 * If you get an error when copying this code into Android studio, update it to match teh package name found
 * in the project's AndroidManifest.xml file.
 **/


import android.os.Bundle;
import android.support.v7.app.AppCompatActivity; …
Run Code Online (Sandbox Code Playgroud)

android android-appcompat android-support-library appcompatactivity androidx

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

具有自定义布局的工具栏:左侧空白

我正在尝试向我的应用程序添加自定义工具栏。这是布局:

<androidx.appcompat.widget.Toolbar
        android:id="@+id/actionbar"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@color/colorAccent"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorPrimary"
            android:orientation="horizontal">

            <ImageButton
                android:id="@+id/back_button"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:background="@drawable/ic_arrow_back_black_24dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="LOGO"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

        </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.appcompat.widget.Toolbar>
Run Code Online (Sandbox Code Playgroud)

但是工具栏左边框和 ConstraintLayout 开始边框之间有一种间隙(粉红色的间隙)在此输入图像描述

我怎样才能删除它?

android android-actionbar android-toolbar androidx

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

RecyclerView 项目未正确显示

在我的项目中,我已经按照我的预期使用了RecyclerViewwhich 显示,layout-preview但问题是当我运行applicationin emulator/未显示device的项目时。RecyclerViewlayout-preview

这是recyclerview的XML。

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".view.LActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:listitem="@layout/rv_sample" />
    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:layout_width="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        android:src="@drawable/ic_add"
        android:id="@+id/fabAdd"
        app:tint="@color/white"
        app:backgroundTint="@color/colorPrimary"
        android:layout_marginEnd="5dp"
        android:layout_marginBottom="5dp"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_height="wrap_content"/>


</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

recyclerview 项目的 XML。

<com.google.android.material.card.MaterialCardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="5dp"
        app:cardCornerRadius="10dp"
        android:minHeight="60dp"
        app:cardUseCompatPadding="true"
        app:strokeColor="@color/design_default_color_secondary_variant"
        app:strokeWidth="1dp">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_gravity="center"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/tvWord"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="5dp"
                android:layout_marginEnd="10dp"
                android:drawableStart="@drawable/arrow_right"
                android:fontFamily="monospace"
                android:text="@{item.word}"
                android:textSize="18sp"
                android:textStyle="bold"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/tvType"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@{item.type}"
                android:layout_marginEnd="10dp"
                app:layout_constraintRight_toRightOf="parent" …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-recyclerview androidx

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

ClassNotFoundException:config_inputEventCompatProcessorOverrideClassName androidx,在 andoridx 上运行崩溃

迁移到在 AndroidX 设备上运行的 AndroidX(29) 后崩溃显示

\n
ClassNotFoundException: config_inputEventCompatProcessorOverrideClassName\n
Run Code Online (Sandbox Code Playgroud)\n

该项目编译并运行时在 andorid10.0 中启动时崩溃\n单击 editText 时出现此错误

\n
NullPointerException: Attempt to invoke virtual method \'java.util.List android.view.InputEventCompatProcessor.processInputEventForCompatibility(android.view.InputEvent)\' on a null object reference\n
Run Code Online (Sandbox Code Playgroud)\n

项目/build.gradle\n

\r\n
\r\n
ClassNotFoundException: config_inputEventCompatProcessorOverrideClassName\n
Run Code Online (Sandbox Code Playgroud)\r\n
\r\n
\r\n

\n

应用程序/build.gradle

\n

\r\n
\r\n
NullPointerException: Attempt to invoke virtual method \'java.util.List android.view.InputEventCompatProcessor.processInputEventForCompatibility(android.view.InputEvent)\' on a null object reference\n
Run Code Online (Sandbox Code Playgroud)\r\n
\r\n
\r\n

\n

gradle-wrapper.properties

\n

\r\n
\r\n
buildscript {\n    repositories {\n        jcenter()\n        maven { url \'https://maven.fabric.io/public\' }\n        maven { url \'https://jitpack.io\' }\n        google()\n    }\n …
Run Code Online (Sandbox Code Playgroud)

java android classnotfoundexception dagger-2 androidx

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

将 Cordova Android 项目迁移到 AndroidX

我目前正在使用 AdMob 测试广告测试混合 Cordova/Android 应用程序。该应用程序使用一个自定义(即内部)插件,我从中可以访问 Google Play 服务 AdMob API。plugin.xml文件的相关位如下

<platform name="android">
 <preference name="PLAY_SERVICES_VERSION" default="17.2.0"/>
 <preference name="ADMOB_APP_ID" default="ca-app-pub-...."/>

 <framework src="com.android.support:appcompat-v7:27.1.0" />
 <framework src="com.google.android.gms:play-services-ads:17.2.0"/>
Run Code Online (Sandbox Code Playgroud)

config.xml应用程序的文件声明以下内容

 <preference name="android-minSdkVersion" value="23" />
 <preference name="android-targetSdkVersion" value="28" />
Run Code Online (Sandbox Code Playgroud)

加载和显示激励视频广告的 Java 代码遵循此处的讨论。

虽然这行得通,但我在这里困扰的是我使用了一个相当古老的play-services-adsAPI。问题是,如果我尝试根据此处显示的说明升级到最新的 API 。我修改后的plugin.xml文件反映了使用最新 API 所需的更改

<platform name="android">
  <preference name="PLAY_SERVICES_VERSION" default="18.3.0"/>
  <preference name="ADMOB_APP_ID" default="ca-app-pub-..."/>

  <framework src="com.android.support:appcompat-v7:28.0.0" />
  <framework src="com.google.android.gms:play-services-ads:18.3.0"/>
Run Code Online (Sandbox Code Playgroud)

问题是我无法再编译该应用程序。Cordova CLI 报告了我在下面显示的一系列问题

带有退出代码 1 错误输出:注意:path\to\app\platforms\android\CordovaLib\src\org\apache\cordova\engine\SystemCookieManager.java 使用或覆盖已弃用的 API。注意:使用 -Xlint:deprecation 重新编译以获取详细信息。path\to\app\platforms\android\app\src\main\AndroidManifest.xml:22:18-86 错误:属性 application@appComponentFactory value=(androidx.core.app.CoreComponentFactory) 来自 [androidx.core:core: …

android cordova google-play-services cordova-cli androidx

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

如何导航到导航抽屉项目单击上的活动

这是我的主要活动,我想导航到导航抽屉项目单击上的活动。我已经检查了实现此目的的旧方法,即使用 switch 语句和使用 onNavigationItemSelected 方法。我知道这是一个经常被问到的问题,但是在阅读了有关堆栈溢出的许多问题和解决方案后,我感到很困惑。我对片段以及通过单击导航抽屉中的项目启动活动所需的内容感到困惑。

MainActivity.java


import android.os.Bundle;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;

import android.view.View;

import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

import com.google.android.material.navigation.NavigationView;

import androidx.drawerlayout.widget.DrawerLayout;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.view.Menu;

public class MainActivity extends AppCompatActivity {

    private AppBarConfiguration mAppBarConfiguration;

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

        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        DrawerLayout drawer = findViewById(R.id.drawer_layout);
        NavigationView navigationView = findViewById(R.id.nav_view);
        // Passing each menu ID as a set of Ids because each
        // menu should be considered as …
Run Code Online (Sandbox Code Playgroud)

java android android-jetpack androidx

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

android.widget.Toolbar 无法转换为 androidx.appcompat.widget.Toolbar,即使情况并非如此

我不确定为什么会收到此错误。我不是从两个不同的工具栏进行投射

这是我的代码:

androidx.appcompat.widget.Toolbar toolbar = (androidx.appcompat.widget.Toolbar) findViewById(R.id.toolbar_header);
        setSupportActionBar(toolbar)
Run Code Online (Sandbox Code Playgroud)

我在这里做错了什么。

这是错误

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.mycontactlist, PID: 12667
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mycontactlist/com.example.mycontactlist.ContactListActivity}: java.lang.ClassCastException: android.widget.Toolbar cannot be cast to androidx.appcompat.widget.Toolbar
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)

Run Code Online (Sandbox Code Playgroud)

android androidx

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

FragmentScenario 未按预期工作

我使用的架构与 Google 示例几乎相同:GithubBrowserSample

该字段被注入到我的 Fragment 类中:

@Inject
lateinit var viewModelFactory: ViewModelProvider.Factory

val viewModel: TrainingListViewModel by viewModels {
    viewModelFactory
}
Run Code Online (Sandbox Code Playgroud)

在我的所有片段测试中,我收到此错误,该错误对应于通过注入实例化的字段:

java.lang.RuntimeException: kotlin.UninitializedPropertyAccessException: lateinit property viewModelFactory has not been initialized
at androidx.test.runner.MonitoringInstrumentation.runOnMainSync(MonitoringInstrumentation.java:441)
at androidx.test.core.app.ActivityScenario.onActivity(ActivityScenario.java:564)
at androidx.fragment.app.testing.FragmentScenario.internalLaunch(FragmentScenario.java:300)
at androidx.fragment.app.testing.FragmentScenario.launchInContainer(FragmentScenario.java:282)
at com.maximesarrato.lafayapp.ui.training.TrainingListFragmentTest.init(TrainingListFragmentTest.kt:213)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at androidx.test.internal.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:76)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at androidx.test.ext.junit.runners.AndroidJUnit4.run(AndroidJUnit4.java:104) …
Run Code Online (Sandbox Code Playgroud)

android kotlin androidx android-fragmentscenario

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

迁移到androidX后,在Retrofit界面中Kapt NonExistentClass异常

我正在使用Retrofit,DaggerGlide为我的应用程序.迁移后androidX,kapt与Dagger和Glide注释处理器完美配合.项目构建和同步成功,但是,当我运行应用程序时,我在我的ApiService接口中获得Kotlin编译器异常,我在其中使用Retrofit注释

ApiService.kt

import retrofit2.Call
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Query

interface ApiService {

    @GET("/popular")
    fun getPopular(@Query("lang") lang: String = LANGUAGE): Call<...>

...

    companion object {
        val STATUS_OK = "ok"
        var LANGUAGE = "en"

        fun create(): ApiService {
            val retrofit = Retrofit.Builder()
                    .addConverterFactory(GsonConverterFactory.create())
                    .baseUrl(...)
                    .build()

            return retrofit.create(ApiService::class.java);
        }
    }
Run Code Online (Sandbox Code Playgroud)

的build.gradle

    apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion …
Run Code Online (Sandbox Code Playgroud)

android kotlin retrofit android-studio-3.2 androidx

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

使用Jetifier工具的AndroidX迁移将支持库转换为RC版本

在迁移到Android X的过程中,tt似乎Jetifier工具将一些第三方库转换为RC版本(4.6版)。

 |    +--- com.facebook.android:facebook-common:4.34.0
|    |    |    +--- com.facebook.android:facebook-core:4.34.0 (*)
|    |    |    +--- com.google.zxing:core:3.3.0
|    |    |    +--- androidx.legacy:legacy-support-v4:1.0.0-rc01
|    |    |    |    +--- androidx.core:core:1.0.0-rc01 -> 1.0.1 (*)
|    |    |    |    +--- androidx.media:media:1.0.0-rc01
|    |    |    |    |    +--- androidx.annotation:annotation:1.0.0-rc01 -> 1.0.0
|    |    |    |    |    +--- androidx.core:core:1.0.0-rc01 -> 1.0.1 (*)
|    |    |    |    |    \--- androidx.versionedparcelable:versionedparcelable:1.0.0-rc01 -> 1.0.0 (*)
|    |    |    |    +--- androidx.legacy:legacy-support-core-utils:1.0.0-rc01 -> 1.0.0 (*)
|    |    |    |    +--- androidx.legacy:legacy-support-core-ui:1.0.0-rc01 …
Run Code Online (Sandbox Code Playgroud)

android android-studio android-jetpack androidx android-jetifier

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