1

I am trying to create custom title bar instead of the title bar provided by the android studio. My activity_main.xml is :

    <?xml version="1.0" encoding="utf-8"?>
<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.hsports.fragmentsinandroid.MainActivity">


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:id="@+id/textTitle"
        android:text="CustomTitle"

        />


    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/duck"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        />



</RelativeLayout>

And my MainActivity class is:

    package com.example.hsports.fragmentsinandroid;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

        setContentView(R.layout.activity_main);

        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.activity_main);
    }
}

My style.xml is:

<resources>

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

    <style name="CustomTheme" parent="@style/Theme.AppCompat">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>

        <item name="android:windowNoTitle">false</item>
    </style>
</resources>

My androidManifest.xml file is:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.hsports.fragmentsinandroid">

    <application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/CustomTheme">
<activity android:name=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
</application>

    </manifest>

After using the above code for the android application I am getting the output as attached in the screenshot. Please have a look at the screenshot attached. I am getting both the title bars (customized+original). I want just the customized one to appear. the attached screenshot is here.

shikher.mishra
  • 155
  • 8
  • 24
  • Possible duplicate of [Try to use Window.FEATURE\_CUSTOM\_TITLE but got Exception:You cannot combine custom titles with other title feature..](http://stackoverflow.com/questions/2686556/try-to-use-window-feature-custom-title-but-got-exceptionyou-cannot-combine-cust) – Code-Apprentice Aug 27 '16 at 19:35
  • Googling the error message will help you find possible solutions. – Code-Apprentice Aug 27 '16 at 19:36
  • I've reported the issue, please star: https://issuetracker.google.com/issues/139883130 – ballzak Aug 23 '19 at 02:18

1 Answers1

0

did you check this cannot combine custom titles with other title features

you should use <item name="android:windowNoTitle">false</item>in your custom theme

if you want to use custom title in your theme, it's necessary to disable FEATURE_NO_TITLE

Community
  • 1
  • 1
Charuක
  • 12,953
  • 5
  • 50
  • 88