简体   繁体   English

Android Studio:活动预览不显示标题栏

[英]Android Studio: Activity preview does not show title bar

i know this question has been made before here , but i have tried the solution given and i don't get the preview look in the exact style like the device does.我知道这里之前已经提出过这个问题,但我已经尝试了给出的解决方案,但我没有像设备那样以确切的样式获得预览外观。

I am using a Samsung Galaxy S3 mini on android version 4.2.2 as my device debugging, it is completely unmodified but i don't understand why, even when i change the theme, the device still looks the same (with the changes made in the activity of course)我在 android 版本 4.2.2 上使用三星 Galaxy S3 mini 作为我的设备调试,它完全没有修改,但我不明白为什么,即使我改变了主题,设备看起来仍然一样(在当然是活动)

the code of the activity is just like any new blank activity活动的代码就像任何新的空白活动

<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>

the preview looks like this预览看起来像这样在此处输入图片说明

but the device looks like this但设备看起来像这样在此处输入图片说明

PS: I am learning android, so i might get confused with the answer PS:我正在学习 android,所以我可能会对答案感到困惑

Had a similar problem.有类似的问题。 In my case, it was just a configuration of the design view.就我而言,它只是设计视图的配置。 After I marked "Show Layout Decorations" it appeared as expected.在我标记“显示布局装饰”后,它按预期出现。 显示布局装饰

  1. It looks like you have a theme defined in your styles.xml file that gives you the above output in your emulator.看起来您在styles.xml文件中定义了一个主题,该主题在您的模拟器中为您提供了上述输出。

  2. Select the same theme (that is defined in your styles.xml) from the AppTheme option in Design view of your activity to make it show your ActionBar.从您活动的设计视图中的AppTheme选项中选择相同的主题(在您的style.xml 中定义),使其显示您的 ActionBar。

在此处输入图片说明

I had the same issue.我遇到过同样的问题。 My problem was that in my styles.xml file I had this我的问题是在我的styles.xml文件中我有这个

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

在此处输入图片说明

Changed it to this and the title bar showed up again.把它改成这个,标题栏又出现了。

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

在此处输入图片说明

Just Go to app/scr/main/res/values/styles.xml and change your AppTheme style to Theme.AppCompat.Light.NoActionBar只需转到 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>

Inorder to make your activity show title bar automatically, you need to extends your activity to AppCompatActivity not an Activity.为了让您的活动自动显示标题栏,您需要将您的活动扩展到 AppCompatActivity 而不是活动。 And also make sure in your manifest.xml you didn't set your theme as还要确保在您的 manifest.xml 中您没有将主题设置为

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

but

android:theme="@style/AppTheme"  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM