studio item icon android menuitem android-actionbar-compat

android - item - IllegalArgumentException Tipo de elemento de carga útil no válido-Con ActionBarCompat



popup menu android (1)

Para mí, esta excepción se produjo solo para una fuente personalizada SpannableString en el título de ActionBar. Sólo se produce en los dispositivos LG. Así que código como este,

public static void setActionBarTitle(ActionBarActivity activity, String title) { SpannableString spannableTitle = new SpannableString(title); spannableTitle.setSpan(new TypefaceSpan(activity, "CustomFont.ttf"), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); ActionBar actionBar = activity.getSupportActionBar(); actionBar.setTitle(isLGDevice() ? title : spannableTitle); } public static boolean isLGDevice() { return (Build.MANUFACTURER.contains("LG") || Build.MODEL.contains("LG")); }

Logcat: http://crashes.to/s/72388b92dd7

Utilizo la barra de acción, como tal, no puedo anular ''onMenuItemSelected'' porque es un método final. Parece que solo le pasa a ALGUNAS personas tambien?

Volví a la verdad en el ''onOptionsItemSelected'' pero no ha servido de ayuda, mientras tanto, presenté un informe de error, esperando que alguien vea esto.

@Override public boolean onOptionsItemSelected(MenuItem item) { if (mDrawerToggle.onOptionsItemSelected(item)) { return true; } switch (item.getItemId()) { case R.id.menu_add_user: Intent intent = new Intent(this, Add_User.class); startActivity(intent); return true; case R.id.menu_about: buildAboutDialog(); return true; case R.id.menu_chat: return true; case R.id.menu_feedback: buildFeedbackDialog("a"); return true; case R.id.menu_show_images: if(appPrefs.getBoolean("showImages", false) == true){ appPrefs.saveBoolean("showImages", false); MenuShowImages.setTitle("Hide images"); MenuShowImages.setIcon(R.drawable.navigation_cancel); } else { appPrefs.saveBoolean("showImages", true); MenuShowImages.setTitle("Show images"); MenuShowImages.setIcon(R.drawable.navigation_accept); } Intent intentab = getIntent(); overridePendingTransition(0, 0); intentab.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); finish(); overridePendingTransition(0, 0); startActivity(intentab); return true; case R.id.menu_news: Intent intent_news = new Intent(this, NewsActivity.class); startActivity(intent_news); return true; case R.id.menu_horny: if(appPrefs.getBoolean("Adult", false) == true){ Hornyitem.setTitle("Filter Normal"); } else { Hornyitem.setTitle("Filter Adult"); } Intent intentaa = getIntent(); overridePendingTransition(0, 0); intentaa.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); finish(); overridePendingTransition(0, 0); startActivity(intentaa); return true; } return true; }

menu.xml:

<menu xmlns:yourapp="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/menu_add_user" android:orderInCategory="0" yourapp:showAsAction="ifRoom" android:icon="@drawable/social_add_person" android:title="@string/menu_add_user"/> <item android:id="@+id/menu_overflow" android:icon="@drawable/ic_menu_moreoverflow_normal_holo_dark" yourapp:showAsAction="always" android:orderInCategory="1" android:title="Show menu"> <menu> <item android:id="@+id/menu_about" android:icon="@drawable/action_about" yourapp:showAsAction="ifRoom" android:title="@string/menu_help" android:orderInCategory="1"/> <item android:id="@+id/menu_feedback" android:icon="@drawable/social_chat" yourapp:showAsAction="ifRoom" android:title="Request feature" android:orderInCategory="1" android:visible="false"/> <item android:id="@+id/menu_show_images" android:icon="@drawable/navigation_accept" yourapp:showAsAction="ifRoom" android:title="@string/show_images" android:orderInCategory="1"/> <item android:id="@+id/menu_noads" android:icon="@drawable/device_access_accounts" yourapp:showAsAction="ifRoom" android:title="Remove ads" android:orderInCategory="1" android:visible="false"/> <item android:id="@+id/menu_news" android:icon="@drawable/location_web_site" yourapp:showAsAction="ifRoom" android:title="@string/menu_news" android:orderInCategory="1" android:visible="false"/> <item android:id="@+id/menu_chat" android:icon="@drawable/location_web_site" yourapp:showAsAction="ifRoom" android:title="Chatroom" android:orderInCategory="1" android:visible="false"/> </menu> </item> </menu>

Instrumentos de cuerda:

<string name="title_activity_news">BroakenMedia News</string> <string name="title_activity_guide">User Guide</string> <string name="title_activity_details">User Details</string> <string name="title_activity_change_background">Change Background</string> <string name="action_settings">Settings</string> <string name="hide_images">Hide images</string> <string name="show_images">Show images</string> <string name="filter_adult_18">Filter Adult (18+)</string> <string name="filter_normal">Filter Normal</string> <string name="dialog_about">About</string> <string name="action_bar_title_norm">Users</string> <string name="menu_news">News</string> <string name="menu_help">Help</string> <string name="menu_add_user">Add sser</string>

configuración de la barra de acción:

String mystring = getString(R.string.action_bar_title_norm); SpannableString s = new SpannableString(mystring); s.setSpan(new TypefaceSpan(this, "cubano"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); actionBar.setTitle(s);