【问题标题】:Android Studio: Activity preview does not show title barAndroid Studio:活动预览不显示标题栏
【发布时间】:2015-05-21 00:30:26
【问题描述】:

我知道这个问题是在here 之前提出的,但我已经尝试了给出的解决方案,但我没有得到与设备完全相同的预览外观。

我在 android 版本 4.2.2 上使用三星 Galaxy S3 mini 作为我的设备调试,它完全没有修改,但我不明白为什么,即使我改变了主题,设备看起来仍然一样(带有当然活动中所做的更改)

活动的代码就像任何新的空白活动一样

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <TextView android:text="@string/hello_world" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>

预览看起来像这样

但设备看起来像这样

PS:我正在学习android,所以我可能会对答案感到困惑

【问题讨论】:

    标签: android android-studio android-titlebar


    【解决方案1】:

    遇到了类似的问题。就我而言,它只是设计视图的配置。在我标记“显示布局装饰”后,它按预期显示。

    【讨论】:

      【解决方案2】:
      1. 您的 styles.xml 文件中似乎定义了一个主题,可以在模拟器中为您提供上述输出。

      2. 从 Activity 的设计视图中的 AppTheme 选项中选择相同的主题(在您的 styles.xml 中定义),使其显示您的 ActionBar。

        李>

      【讨论】:

      • 这是如何在文件中定义的?...当我选择我正在使用的相同主题时,它不会改变
      • @OscarReyes 我知道这已经很老了,但是你解决了这个问题吗?
      【解决方案3】:

      我有同样的问题。我的问题是在我的styles.xml 文件中我有这个

      <item name="windowActionBar">true</item>
      <item name="windowNoTitle">true</item>
      

      改成这个,标题栏又出现了。

      <item name="windowActionBar">true</item>
      <item name="windowNoTitle">false</item>
      

      【讨论】:

        【解决方案4】:

        只需转到 app/scr/main/res/values/styles.xml 并将您的 AppTheme 样式更改为 Theme.AppCompat.Light.NoActionBar

           <!-- Base application theme. -->
        <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
            <!-- Customize your theme here. -->
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>
        </style>
        

        【讨论】:

          【解决方案5】:

          为了使您的活动自动显示标题栏,您需要将活动扩展到 AppCompatActivity 而不是活动。并确保在您的 manifest.xml 中您没有将主题设置为

          android:theme="@style/AppTheme.NoActionBar"
          

          但是

          android:theme="@style/AppTheme"  
          

          【讨论】:

            猜你喜欢
            • 2023-03-13
            • 2021-05-17
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-04-02
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多