0

不知道发生了什么,我无法再在 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>

例如。它不会显示操作栏。

4

2 回答 2

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 或更低,请尝试查看官方文档

于 2013-10-22T05:24:41.043 回答
0

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

于 2015-03-29T05:09:44.427 回答