所以我是Android编程新手
我要添加两个操作栏,但是当我添加第二个操作栏时,它会填充旧的操作栏,而不是新的操作栏。
我已经使用了全息灯主题。
这是我的清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.orionpreneur"
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/AppTheme"
android:uiOptions="splitActionBarWhenNarrow">
<!-- Splash Screen Activity -->
<activity
android:name=".SplashScreen"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Login Activity -->
<activity
android:name=".LoginActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name=".SecondActivity"
android:label="@string/about_us"
android:parentActivityName=".LoginActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.orionpreneur.MainActivity" />
</activity>
<activity
android:name=".About"
android:label="@string/title_activity_about"
android:parentActivityName=".LoginActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.orionpreneur.MainActivity" />
</activity>
</application>
</manifest>
这是我的main_activity_menu.xml代码
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Search, should appear as action button -->
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
android:showAsAction="always" />
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/about"
android:title="@string/about"
android:showAsAction="always"/>
</menu>
这是我的MainActivity.java代码
package com.example.orionpreneur;
import android.app.ActionBar;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class LoginActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
}
@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_activity_menu, menu);
return super.onCreateOptionsMenu(menu);
}
@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.
switch (item.getItemId()) {
case R.id.action_search:
Toast.makeText(this, "you've pressed the search button !", Toast.LENGTH_SHORT).show();
return true;
case R.id.about:
Intent in = new Intent(this, About.class );
startActivity(in);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
我希望将搜索按钮添加到像这样的分隔栏中
https://developer.android.com/images/training/basics/actionbar-actions.png
我绝望,抱歉,如果我的问题已经被问到了。
谢谢:)))
答案 0 :(得分:0)
*删除此*
android:uiOptions="splitActionBarWhenNarrow"
android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen