gpt4 book ai didi

java - float 操作按钮未在 API < 21 上呈现

转载 作者:搜寻专家 更新时间:2023-11-01 09:30:14 25 4
gpt4 key购买 nike

编辑:我已经更新到最新的 Android 支持库,但仍然收到错误。

我知道这个问题是多余的,我已经研究了所有关于 SO 的问题,但我仍然无法确定为什么我的 FAB 没有在 API 19 上呈现。我知道 API 21 有相当大的变化,并且向后兼容性已解决使用 AppCompat 库。我还了解所需的关键更改正在更改

        android:backgroundTint="@color/actionRed"

            app:backgroundTint="@color/actionRed"

我已经做到了。

这可能与我的主题有关,因为我仍在学习 Android 主题和 Material 设计的基础知识。下面是描述我的库、XML 和我收到的错误的所有相关代码:

Manifest(我之前使用的是 NoActionBar 主题,尝试更改为 Theme.AppCompat):

    <application
android:name="android.support.multidex.MultiDexApplication"
android:allowBackup="true"
android:icon="@drawable/xxxxxxxx"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat">

XML:

        <android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.FloatingActionButton
android:visibility="visible"
android:id="@+id/myFAB"
android:clickable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:backgroundTint="@color/actionRed"
android:layout_gravity="bottom|end"
android:layout_marginEnd="6dp"
android:layout_marginRight="6dp"
android:layout_marginBottom="6dp"
app:srcCompat="@drawable/ic_add_white_24dp"
app:elevation="4dp"
/>

应用级 Gradle:

android {
compileSdkVersion 26
buildToolsVersion '26.0.2'

defaultConfig {
vectorDrawables.useSupportLibrary = true
applicationId "xxxxxxxxxxxx"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true

}


// Support library
compile "com.android.support:design:$supportLibVersion"
compile "com.android.support:cardview-v7:$supportLibVersion"
compile "com.android.support:support-v4:$supportLibVersion"
compile "com.android.support:appcompat-v7:$supportLibVersion"

根 Gradle :

ext {
supportLibVersion = "27.0.2"
playServicesVersion = "11.4.2"
}

Drawable(是不是因为我用的是我自己的FAB图片?我想要红色按钮带白色“+”号):

enter image description here

错误:

1:28.981 3807-3807/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: xxxxxxxxxxxxx, PID: 3807
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.troychuinard.fanpolls/com.troychuinard.fanpolls.HomeActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class android.support.design.widget.FloatingActionButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class android.support.design.widget.FloatingActionButton
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.troychuinard.fanpolls.HomeActivity.onCreate(HomeActivity.java:66)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
at android.app.ActivityThread.access$800(ActivityThread.java:135) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5001) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at com.troychuinard.fanpolls.HomeActivity.onCreate(HomeActivity.java:66) 
at android.app.Activity.performCreate(Activity.java:5231) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
at android.app.ActivityThread.access$800(ActivityThread.java:135) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5001) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.NoSuchMethodError: android.support.v4.content.res.ConfigurationHelper.getScreenWidthDp
at android.support.design.widget.FloatingActionButton.getSizeDimension(FloatingActionButton.java:442)
at android.support.design.widget.FloatingActionButton.getSizeDimension(FloatingActionButton.java:434)
at android.support.design.widget.FloatingActionButton$ShadowDelegateImpl.getRadius(FloatingActionButton.java:819)
at android.support.design.widget.FloatingActionButtonGingerbread.setBackgroundDrawable(FloatingActionButtonGingerbread.java:92)
at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:181)
at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:153)
at java.lang.reflect.Constructor.constructNative(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
at android.view.LayoutInflater.createView(LayoutInflater.java:594) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at com.troychuinard.fanpolls.HomeActivity.onCreate(HomeActivity.java:66) 
at android.app.Activity.performCreate(Activity.java:5231) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
at android.app.ActivityThread.access$800(ActivityThread.java:135) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5001) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
at
dalvik.system.NativeStart.main(Native Method) 
12-06 23:41:28.981 569-870/? W/ActivityManager: Force finishing
activity xxxxxxxxxxxx/.HomeActivity

我们将不胜感激任何帮助、 Material 设计资源、AppCompat、向后兼容性或任何相关建议。

最佳答案

您必须更换:

android:src

与:

app:srcCompat

关于java - float 操作按钮未在 API < 21 上呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47702221/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com