Issues in customizing toolbar in Android
Clash Royale CLAN TAG#URR8PPP
Issues in customizing toolbar in Android
I wanted to achieve the following task
I successfully removed the default toolbar but while building the custom toolbar I'm not able to
I tried out the existing solutions provided to the above problems at stack overflow but nothing seemed to be helpful in my case
Here's toolBar.xml file
enter code here
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.toolbar
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:id="@+id/toolbarC"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:theme="@style/Mystyle"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleTextColor="#ffffff">
</android.support.v7.widget.toolbar>
Here is my main xml file
enter code here`
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:layout="http://schemas.android.com/apk/res-auto"
android:background="#3dcc24">
<include
layout="@layout/clubs_tool_bar" />
</LinearLayout>
Here's is my styles.xml file
<resources>
<!-- 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>
<item name="ColorTemp">@color/ColorTemp</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay"
parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="Mystyle" parent="ThemeOverlay.AppCompat.ActionBar">
<item name = "android:textSize">30sp</item>
</style>
</resources>
This is what my screen looks like
1 Answer
1
You need to address the appropriate class so use android.support.v7.widget.Toolbar
android.support.v7.widget.Toolbar
<android.support.v7.widget.Toolbar
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:id="@+id/toolbarC"
app:title="YourTitle"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:theme="@style/Mystyle"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleTextColor="#ffffff"/>
instead of
android.support.v7.widget.toolbar
you have to use the title attribute ` app:title="yourTitle"`
– Pavneet_Singh
Sep 26 '17 at 14:59
I got it ! Problem solved ! Thank you so much for the help !
– Honey Khandelwal
Sep 26 '17 at 15:02
you can further add your own textView inside toolbar instead of
app:title
to further manipulate it if you want , i am glad that i could help , happy coding– Pavneet_Singh
Sep 26 '17 at 15:04
app:title
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I made the required changes. Now the toolbar is empty, how do I add a title?
– Honey Khandelwal
Sep 26 '17 at 14:57