Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

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

like image 605
Oscar Reyes Avatar asked May 21 '15 00:05

Oscar Reyes


People also ask

How do you set a title in an activity?

To change the title of an activity (to show a more custom title for a certain activity than the application title), you can set the new title either through calling setTitle("foo") on the activity or by setting android:label="@string/price_after_rebate" in your activity style.

How do I show and hide the title bar?

So basically we just need to change DarkActionBar to NoActionBar. NoActionBar theme prevents the app from using the native ActionBar class to provide the app bar. Thus it removes the title of every activity.

Which of the following attribute is used to hide the title of an activity in the manifest XML file *?

Just use getActionBar(). hide(); in your main activity onCreate() method. Save this answer.


2 Answers

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

like image 185
DannyL Avatar answered Oct 20 '22 11:10

DannyL


  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

like image 42
Gissipi_453 Avatar answered Oct 20 '22 10:10

Gissipi_453