Zorgan
Zorgan

Reputation: 9123

How can I edit the header in a blank activity?

I'm very new to android studio but I can't see any XML of the header, so I can't edit it. I want to do things like change it's position, height etc so is there any way I can do this?

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    tools:context="com.example.zorgan.app.MainActivity"
    tools:layout_editor_absoluteY="81dp"
    tools:layout_editor_absoluteX="0dp">


</android.support.constraint.ConstraintLayout>

Upvotes: 0

Views: 7094

Answers (3)

tahsinRupam
tahsinRupam

Reputation: 6405

To add ToolBar to your activity:

1) Create a new layout called new_activity_main.xml and add the following code:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:fitsSystemWindows="true"
   android:orientation="vertical">

 <android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:minHeight="?attr/actionBarSize"  
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:titleTextColor="@android:color/white"
    android:background="?attr/colorPrimary">

       <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="My Title"
        android:layout_gravity="center"
        android:id="@+id/toolbar_title" />

 </android.support.v7.widget.Toolbar>

 <!-- include your activity_main.xml here  -->

 <include layout="@layout/activity_main" />

</LinearLayout>

2) Create a style to disable ActionBar in style.xml :

 <style name="AppTheme.NoActionBar">
   <item name="windowActionBar">false</item>
   <item name="windowNoTitle">true</item>
 </style>

3) Set this style to your Activity in manifest:

  <activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:theme="@style/AppTheme.NoActionBar">

4) Set layout of activity:

   setContentView(R.layout.new_activity_main);

5) And add the following code to onCreate(). First initiate toolbar then disable default title:

Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);

Hope it helps. (Kudos to this answer).

Upvotes: 1

user5874734
user5874734

Reputation:

Just add setTitle("any");below setContentView in your activity

Upvotes: 0

aaroncio
aaroncio

Reputation: 307

If you only want to change the name and simple stuff go to the AndroidManifest.xml file under application tag you can change basic things.

If you are talking about the Toolbar, you can check this tutorial https://guides.codepath.com/android/Using-the-App-Toolbar

Hope it helps.

Upvotes: 0

Related Questions