视图上没有ActionBar

时间:2013-10-22 05:14:45

标签: android android-actionbar

不确定发生了什么,我无法在Android Studio中获得带有操作栏的应用。

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    tools:ignore="MergeRootFrame">

    <TextView
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:text="hello"/>
</LinearLayout>
例如,

。它不会显示操作栏。

2 个答案:

答案 0 :(得分:0)

如果这是您的整个XML,则缺少节点theme。例如:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:theme="@style/Theme.AppCompat.Light"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    tools:ignore="MergeRootFrame">

    <TextView
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:text="hello"/>
</LinearLayout>

这是API级别11或更高级别的解决方案。在这里,您只需使用其中一个Holo主题来添加ActoinBar 如果您使用API​​级别10或更低级别,请尝试查看official Docs

答案 1 :(得分:0)

我遇到了同样的问题。 我认为你应该让你的活动在Android studio中扩展ActionBarActivity(而不是Activity)。