项目不会直接显示在操作栏中作为操作按钮

时间:2014-09-19 08:13:22

标签: android android-activity

我已经按照tutorail http://developer.android.com/guide/topics/ui/actionbar.html创建了一个操作栏,其中的项目apear直接在操作栏中作为操作按钮。但我的项目不会显示为按钮..这就是它的样子:(项目:删除,编辑,添加) 知道为什么吗?

enter image description here

我的设备是galaxy s4

这是我的代码:

活动:

public class SingleTask extends ActionBarActivity{ 

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_single_task);

    final android.support.v7.app.ActionBar actionbar = getSupportActionBar(); 

     actionbar.show();
     //some more things .....

 }
 @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.task_menu, menu);

        return super.onCreateOptionsMenu(menu);
    }               
}

task_menu.xml:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@+id/action_delete"
      android:icon="@drawable/ic_action_remove"
      android:orderInCategory="101"
      android:title="@string/action_delete"
      android:showAsAction="ifRoom"/>

<item android:id="@+id/action_edit"
      android:icon="@drawable/ic_action_edit"
      android:title="@string/action_edit"
        android:orderInCategory="102"
      android:showAsAction="ifRoom"/>

<item android:id="@+id/create_new"
      android:icon="@drawable/ic_action_new"
      android:title="@string/action_add"
        android:orderInCategory="103"
      android:showAsAction="ifRoom" />

menifest:

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

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Theme.AppCompat.Light" >
    <activity
        android:name="shiransarusi.com.getset.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>
    <activity
        android:name="shiransarusi.com.login.StudentLogIn"
        android:label="@string/title_activity_student_log_in" >
    </activity>
    <activity
        android:name="shiransarusi.com.getset.StudentMenu"
        android:label="@string/title_activity_student_menu" >
    </activity>
    <activity
        android:name="shiransarusi.com.login.StudentRegister"
        android:label="@string/title_activity_student_register" >
    </activity>
    <activity
        android:name="shiransarusi.com.getset.JSONParser"
        android:label="@string/title_activity_student_register" >
    </activity>
    <activity
        android:name="shiransarusi.com.getset.imageAdapter"
        android:label="@string/title_activity_image_adapter" >
    </activity>
    <activity
        android:name="shiransaruci.com.tasks.AllTasksActivity"
        android:label="@string/title_activity_all_tasks" >
    </activity>
    <activity
        android:name="shiransaruci.com.tasks.EditTaskActivity"
        android:label="@string/title_activity_edit_task" >
    </activity>
    <activity
        android:name="shiransaruci.com.tasks.NewTaskActivity"
        android:label="@string/title_activity_new_task" >
    </activity>
    <activity
        android:name="shiransaruci.com.tasks.SingleTask"
        android:label="@string/title_activity_single_task" >
    </activity>
  </application>    
  <!--   Internet Permissions -->
 <uses-permission android:name="android.permission.INTERNET" />

 </manifest>

1 个答案:

答案 0 :(得分:0)

文档:menu-resource

您可以尝试:

android:showAsAction="always|withText"

OR

android:showAsAction="always"