操作栏不拆分

时间:2015-06-02 16:48:56

标签: android action

我已经搜索并尝试了所有解决方案,但我的操作栏仍然没有拆分。额外的项目溢出到溢出菜单,我不明白为什么。请帮帮我。感谢!!!!!!!

的Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.apptutorial"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="21" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Theme.AppCompat" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" 
        android:uiOptions="splitActionBarWhenNarrow">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <meta-data
            android:name="android.support.UI_OPTIONS"
            android:value="splitActionBarWhenNarrow"
        />
    </activity>
</application>

MainActivity.java

package com.example.apptutorial;

import android.support.v7.app.*;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

@SuppressWarnings("deprecation")
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;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}

menu.xml文件

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.apptutorial.MainActivity" >

<item
    android:id="@+id/action_settings"
    android:orderInCategory="100"
    android:title="@string/action_settings"
    app:showAsAction="never"/>

<item
    android:id="@+id/phone"
    android:title="@string/phone"
    android:icon="@drawable/ic_action_call"
    app:showAsAction="ifRoom|withText"
    />

<item
    android:id="@+id/computer"
    android:title="@string/computer"
    android:icon="@drawable/ic_action_computer"
    app:showAsAction="ifRoom|withText"
    />

<item
    android:id="@+id/email"
    android:title="@string/email"
    android:icon="@drawable/ic_action_mail"
    app:showAsAction="ifRoom|withText"
    />

<item
    android:id="@+id/video"
    android:title="@string/video"
    android:icon="@drawable/ic_action_video"
    app:showAsAction="ifRoom|withText"
    />

1 个答案:

答案 0 :(得分:2)

Android 5.0+上的原生操作栏或appcompat-v7操作栏后端不支持拆分操作栏。您正在使用appcompat-v7;因此,您没有拆分操作栏。

将您的应用重新设计为不需要拆分操作栏,或者安排将您自己的Toolbar放在UI底部,其中包含您想要的项目。