Join FlipAndroid.COM Telegram Group: https://t.me/joinchat/F_aqThGkhwcLzmI49vKAiw


Botón de acción flotante y error de inflación de biblioteca de diseño

Estoy usando la biblioteca de soporte de diseño

defaultConfig { vectorDrawables.useSupportLibrary = true ... } dependencies { compile 'com.android.support:design:23.4.0' compile 'com.android.support:support-v4:23.4.0' ... } 

Cuando estoy agregando FloatingActionButton

 <android.support.design.widget.FloatingActionButton android:layout_gravity="right" android:layout_margin="20dp" android:tint="#fff" android:src="@drawable/ic_menu_manage" app:backgroundTint="#b3000000" android:layout_width="wrap_content" android:layout_height="wrap_content" /> 

A uno de mis diseños obtengo este error

 Caused by: java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library. 

Aquí está mi actividad principal ( it has navigation drawer )

 public class MapNavActivity extends AppCompatActivity 

Sé que debería funcionar si cambio AppCompatActivity a Activity

Sin embargo esto no funciona para mí. Esta es la actividad definida en el archivo de manifiesto

 <activity android:name=".MapNavActivity" android:label="@string/title_activity_map_nav" android:theme="@style/AppTheme.NoActionBarMain" /> 

Y aquí está el tema en el archivo styles.xml

 <style name="AppTheme.NoActionBarMain" parent="Theme.AppCompat.Light.NoActionBar"> <item name="windowActionBar">false</item> <item name="windowNoTitle">true</item> </style> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> 

Estoy atascado con este problema casi 5 horas. Alguien sabe cómo resolver esto?

Archivo de manifiesto EDIT

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="rojus.zvyjybos.com.zvejybosrojus2"> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.CALL_PHONE" /> <uses-feature android:name="android.hardware.sensor.accelerometer" /> <uses-feature android:name="android.hardware.sensor.compass" /> <application android:name=".start.App" android:allowBackup="true" android:icon="@drawable/logo" android:label="@string/app_name" android:largeHeap="true" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".start.MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MapNavActivity" android:label="@string/title_activity_map_nav" android:theme="@style/AppTheme.NoActionBarMain" /> <activity android:name=".menu_activities.LakeDetailActivity" android:theme="@style/AppTheme.NoActionBarMain" /> <activity android:name=".menu_activities.FishActivity" android:theme="@style/AppTheme.NoActionBarMain" /> <activity android:name=".menu_activities.BitesActivity" android:theme="@style/AppTheme.NoActionBarMain" /> <activity android:name=".menu_activities.FishingMethodsActivity" android:theme="@style/AppTheme.NoActionBarMain" /> <activity android:name=".fragments.MyFishingPlanDetailList" android:theme="@style/AppTheme.NoActionBarMain" /> <activity android:name=".menu_activities.DetailPlaceActivity" android:theme="@style/AppTheme.NoActionBarMain" /> <activity android:name=".augumented_reality.AugumentedActivity" /> <activity android:name=".start.MainMenu" android:theme="@style/AppTheme.NoActionBarMain" /> </application> </manifest> 

También añadiré una excepción completa

 Process: rojus.zvyjybos.com.zvejybosrojus2, PID: 26070 java.lang.RuntimeException: Unable to start activity ComponentInfo{rojus.zvyjybos.com.zvejybosrojus2/rojus.zvyjybos.com.zvejybosrojus2.MapNavActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class android.support.design.widget.FloatingActionButton at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2441) at android.app.ActivityThread.access$800(ActivityThread.java:162) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5431) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:914) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707) Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class android.support.design.widget.FloatingActionButton at android.view.LayoutInflater.createView(LayoutInflater.java:633) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) at android.view.LayoutInflater.parseInclude(LayoutInflater.java:916) at android.view.LayoutInflater.rInflate(LayoutInflater.java:802) at android.view.LayoutInflater.inflate(LayoutInflater.java:504) at android.view.LayoutInflater.inflate(LayoutInflater.java:414) at android.view.LayoutInflater.inflate(LayoutInflater.java:365) at rojus.zvyjybos.com.zvejybosrojus2.map.MapFragment.customMapView(MapFragment.java:416) at rojus.zvyjybos.com.zvejybosrojus2.map.MapFragment.onViewCreated(MapFragment.java:322) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617) at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:339) at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:601) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1236) at android.app.Activity.performStart(Activity.java:6068) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2342) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2441) at android.app.ActivityThread.access$800(ActivityThread.java:162) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5431) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:914) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.newInstance(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:288) at android.view.LayoutInflater.createView(LayoutInflater.java:607) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) at android.view.LayoutInflater.parseInclude(LayoutInflater.java:916) at android.view.LayoutInflater.rInflate(LayoutInflater.java:802) at android.view.LayoutInflater.inflate(LayoutInflater.java:504) at android.view.LayoutInflater.inflate(LayoutInflater.java:414) at android.view.LayoutInflater.inflate(LayoutInflater.java:365) at rojus.zvyjybos.com.zvejybosrojus2.map.MapFragment.customMapView(MapFragment.java:416) at rojus.zvyjybos.com.zvejybosrojus2.map.MapFragment.onViewCreated(MapFragment.java:322) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617) at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:339) at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:601) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1236) at android.app.Activity.performStart(Activity.java:6068) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2342) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2441) at android.app.ActivityThread.access$800(ActivityThread.java:162) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5431) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:914) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707) Caused by: java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library. at android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:34) at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:116) at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:110) at java.lang.reflect.Constructor.newInstance(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:288) at android.view.LayoutInflater.createView(LayoutInflater.java:607) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) at android.view.LayoutInflater.parseInclude(LayoutInflater.java:916) at android.view.LayoutInflater.rInflate(LayoutInflater.java:802) at android.view.LayoutInflater.inflate(LayoutInflater.java:504) at android.view.LayoutInflater.inflate(LayoutInflater.java:414) at android.view.LayoutInflater.inflate(LayoutInflater.java:365) at rojus.zvyjybos.com.zvejybosrojus2.map.MapFragment.customMapView(MapFragment.java:416) at rojus.zvyjybos.com.zvejybosrojus2.map.MapFragment.onViewCreated(MapFragment.java:322) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617) at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:339) at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:601) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1236) at android.app.Activity.performStart(Activity.java:6068) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2342) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2441) at android.app.ActivityThread.access$800(ActivityThread.java:162) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5431) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:914) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707) 

  • ¿Cómo hacer el FAB evitar ser movido en ViewPager, sin embargo, ser una parte del fragmento dentro?
  • 2 Solutions collect form web for “Botón de acción flotante y error de inflación de biblioteca de diseño”

    Acabo de probar su código en un proyecto nuevo y está funcionando bien en mi máquina. Asegúrese de que compile 'com.android.support:appcompat-v7:23.4.0' esté en su archivo build.gradle luego haga una reconstrucción y vea si eso ayuda. También compruebe su encargado del SDK para ver si usted tiene algunas viejas actualizaciones que usted no ha instalado todavía.

    Ok, vaya a la forma sencilla.

    Primero agrega dependencia a tu build.gradle.

     dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:design:23.1.1' 

    }

    Luego abra su archivo XML y agregue Botón de acción flotante.

     <android.support.design.widget.FloatingActionButton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" android:src="@android:drawable/ic_dialog_email" /> 

    Luego abra su archivo .java e inicialice el botón flotante

     FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Click action // write you code here. } }); 

    Luego Limpie su proyecto y ejecútelo.

    Espero que esta solución le ayude.

    FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.