android–ActionBar项目始终显示在溢出菜单中

android–ActionBar项目始终显示在溢出菜单中,第1张

概述我正在尝试在 *** 作栏中添加 *** 作项,但项目总是添加到溢出列表中,即使有很多空间.有什么建议来解决这个问题?这应该是这样的main.xml中<menuxmlns:android="http://schemas.android.com/apkes/android"xmlns:app="http://schemas.android.com/apkes-auto"><item

我正在尝试在 *** 作栏中添加 *** 作项,但项目总是添加到溢出列表中,即使有很多空间.有什么建议来解决这个问题?

这应该是这样的

main.xml中

<menu xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:app="http://schemas.androID.com/apk/res-auto">    <item        androID:ID="@+ID/action_refresh"        androID:icon="@drawable/ic_action_refresh"        androID:showAsAction="ifRoom"        androID:title="@string/action_refresh" />    <item        androID:ID="@+ID/action_search"        androID:icon="@drawable/ic_action_search"        androID:showAsAction="ifRoom"        androID:title="@string/action_search" />    <item        androID:ID="@+ID/action_settings"        androID:title="@string/action_settings"        app:showAsAction="never" /></menu>

MainActivity.java

public class MainActivity extends ActionBaractivity {    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);    }    @OverrIDe    public boolean onCreateOptionsMenu(Menu menu) {        // Inflate the menu; this adds items to the action bar if it is present.        getMenuInflater().inflate(R.menu.main, menu);        return true;    }}

AndroIDManifest.xml中

<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID"    package="com.example.actionbardemo.app" >    <application        androID:allowBackup="true"        androID:icon="@drawable/ic_launcher"        androID:label="@string/app_name"        androID:theme="@style/Apptheme" >        <activity            androID:name="com.example.actionbardemo.app.MainActivity"            androID:label="@string/app_name" >            <intent-filter>                <action androID:name="androID.intent.action.MAIN" />                <category androID:name="androID.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application></manifest>

的build.gradle

apply plugin: 'androID'androID {    compileSdkVersion 19    buildToolsversion "19.0.3"    defaultConfig {        minSdkVersion 8        targetSdkVersion 19        versionCode 1        versionname "1.0"    }    buildTypes {        release {            runProguard false            proguardfiles getDefaultProguardfile('proguard-androID.txt'), 'proguard-rules.txt'        }    }}dependencIEs {    compile 'com.androID.support:support-v4:19.0.1'    compile 'com.androID.support:appcompat-v7:19.0.1'    compile filetree(dir: 'libs', include: ['*.jar'])}

解决方法:

我的应用程序使用支持库来兼容低至AndroID 2.2的版本,所以我必须定义自己的XML命名空间并使用该命名空间作为属性前缀

解决方案就是这样,我正在编写这个androID:showAsAction =“ifRoom”但我应该有app:showAsAction =“ifRoom”

<menu xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:app="http://schemas.androID.com/apk/res-auto">    <item        androID:ID="@+ID/action_refresh"        androID:icon="@drawable/ic_action_refresh"        app:showAsAction="ifRoom"        androID:title="@string/action_refresh" />    <item        androID:ID="@+ID/action_search"        androID:icon="@drawable/ic_action_search"        app:showAsAction="ifRoom"        androID:title="@string/action_search" />    <item        androID:ID="@+ID/action_settings"        androID:title="@string/action_settings"        app:showAsAction="never" /></menu>
总结

以上是内存溢出为你收集整理的android – ActionBar项目始终显示在溢出菜单中全部内容,希望文章能够帮你解决android – ActionBar项目始终显示在溢出菜单中所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1097437.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存