我正在开发一个Android应用程序,并且需要具有相同的操作栏。
我提到了很多网站并获得了输出,但是它就像一个列表,而不是我需要的操作栏
main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/home"
android:title="@string/home"
android:icon="@drawable/home"
android:showAsAction="ifRoom|withText" />
<item
android:id="@+id/search"
android:title="@string/search"
android:icon="@drawable/search"
android:showAsAction="ifRoom|withText" />
<item
android:id="@+id/user"
android:title="@string/profile"
android:icon="@drawable/user"
android:showAsAction="ifRoom|withText" />
<item
android:id="@+id/notification"
android:title="@string/notification"
android:icon="@drawable/world"
android:showAsAction="ifRoom|withText" />
<item
android:id="@+id/sell"
android:title="@string/sell"
android:icon="@drawable/book"
android:showAsAction="ifRoom|withText" />
</menu>
activity.java
public class Home extends ActionBarActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_home);
//android.app.ActionBar actionBar = getActionBar();
//actionBar.show();
}@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) {
super.onOptionsItemSelected(item);
switch(item.getItemId()){
case R.id.home:
Toast.makeText(getBaseContext(), "You selected Phone", Toast.LENGTH_SHORT).show();
break;
case R.id.search:
Toast.makeText(getBaseContext(), "You selected Computer", Toast.LENGTH_SHORT).show();
break;
case R.id.user:
Toast.makeText(getBaseContext(), "You selected Gamepad", Toast.LENGTH_SHORT).show();
break;
case R.id.notification:
Toast.makeText(getBaseContext(), "You selected Camera", Toast.LENGTH_SHORT).show();
break;
case R.id.sell:
Toast.makeText(getBaseContext(), "You selected Video", Toast.LENGTH_SHORT).show();
break;
}
return true;
}
}
表现
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.parseprc"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat" >
<activity
android:name="com.example.parseprc.Main_activity"
android:label="@string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.parseprc.Login"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>
<activity
android:name="com.example.parseprc.register"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>
<activity
android:name="com.example.parseprc.Home"
android:label="@string/app_name"
android:uiOptions="splitActionBarWhenNarrow">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
<meta-data android:name="android.support.UI_OPTIONS"
android:value="splitActionBarWhenNarrow" />
</activity>
<activity
android:name="com.example.parseprc.Forgotpassword"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>
</application>
</manifest>
我需要类似instagram和twitter的actionbar输出
但是我所得到的只是选项列表
最佳答案
你可以尝试改变
android:showAsAction="ifRoom|withText"
至
android:showAsAction="always"