gpt4 book ai didi

android - IllegalArgumentException 无效的有效负载项类型 - 使用 ActionBarCompat

转载 作者:IT老高 更新时间:2023-10-28 23:16:13 26 4
gpt4 key购买 nike

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

我使用操作栏兼容,因此我无法覆盖“onMenuItemSelected”,因为它是 final方法。似乎也只发生在某些人身上?

我在“onOptionsItemSelected”上返回了 true,但没有帮助,同时提交了一个错误报告,希望有人能看到。

 @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>

字符串:

    <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>

Action 栏设置标题:

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);

最佳答案

对我来说,这个异常只发生在 ActionBar title 中的自定义字体 SpannableString 上。它仅发生在 LG 设备中。所以我这样编码,

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"));
}

关于android - IllegalArgumentException 无效的有效负载项类型 - 使用 ActionBarCompat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19617897/

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