Android Studio: Activity preview does not show title bar
Asked Answered
G

5

8

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)

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 enter image description here

but the device looks like this enter image description here

PS: I am learning android, so i might get confused with the answer

Gilud answered 21/5, 2015 at 0:30 Comment(0)
K
30

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.Show Layout Decorations

Keown answered 5/2, 2019 at 17:8 Comment(0)
S
1
  1. It looks like you have a theme defined in your styles.xml file that gives you the above output in your emulator.

  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.

enter image description here

Sleepy answered 21/5, 2015 at 1:30 Comment(2)
how is this defined in the file?... and when i select the same theme i'm using, it does not changeGilud
@OscarReyes I know this is very old, but have you solved the issue?Selfexcited
L
1

Inorder to make your activity show title bar automatically, you need to extends your activity to AppCompatActivity not an Activity. And also make sure in your manifest.xml you didn't set your theme as

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

but

android:theme="@style/AppTheme"  
Larochelle answered 20/6, 2016 at 18:5 Comment(0)
E
1

I had the same issue. My problem was that in my styles.xml file I had this

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

enter image description here

Changed it to this and the title bar showed up again.

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

enter image description here

Expressage answered 6/10, 2020 at 13:55 Comment(0)
B
0

Just Go to app/scr/main/res/values/styles.xml and change your AppTheme style to 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>
Baldheaded answered 5/5, 2016 at 16:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.