1

I'm trying to edit the Title text size because it changes when in landscape screen. I found changing the dimension in SP can solve the problem. So I did this...

added a style in style.xml

<style name="Toolbar.TitleText"
    parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
    <item name="android:textSize">30sp</item>
</style>

and then in app_bar_main.xml under android.support.v7.widget.Toolbar i added this line

app:titleTextAppearance="@style/Toolbar.TitleText"

Now it gives the desired result on Main activity but all others activities are same. I have around 10 activities in my app. How can I change all the activities' Title? Please help. Thanks in advance.

my manifest.xml

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:label="@string/title_main"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity
        android:name=".splash"
        android:screenOrientation="portrait"
        android:theme="@style/SplashTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".ch_1"
        android:label="@string/ch_1" />
    <activity
        android:name=".ch_2"
        android:label="@string/ch_2" />
    <activity
        android:name=".ch_3"
        android:label="@string/ch_3" />
    <activity
        android:name=".ch_4"
        android:label="@string/ch_4" />
    <activity
        android:name=".ch_5"
        android:label="@string/ch_5" />
    <activity
        android:name=".ch_6"
        android:label="@string/ch_6" />
    <activity
        android:name=".ch_7"
        android:label="@string/ch_7" />
    <activity
        android:name=".ch_8"
        android:label="@string/ch_8" />
    <activity
        android:name=".ch_9"
        android:label="@string/ch_9" />
    <activity
        android:name=".ch_10"
        android:label="@string/ch_10" />
    <activity
        android:name=".ch_11"
        android:label="@string/ch_11" />
    <activity android:name=".ch_12"
        android:label="@string/ch_12" />
    <activity
        android:name=".ch_13"
        android:label="@string/ch_13" />
    <activity
        android:name=".ch_14"
        android:label="@string/ch_14" />
    <activity
        android:name=".ch_15"
        android:label="@string/ch_15" />
    <activity android:name=".view" />
</application>

my style.xml

<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>
    <item name="android:windowBackground">@color/white</item>
    <item name="colorButtonNormal">@color/colorPrimary</item>
    <item name="android:textAppearanceButton">@style/TextAppearance.AppCompat.Button.Custom</item>
</style>


<style name="Toolbar.TitleText"
    parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
    <item name="android:textSize">24sp</item>
</style>


<style name="TextAppearance.AppCompat.Button.Custom">
    <item name="android:textColor">@color/white</item>
    <item name="android:textSize">28sp</item>
</style>


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

<style name="ActionButtonStyle" parent="@android:style/Widget.Holo.ActionButton">
    <item name="android:minWidth">0dip</item>
    <item name="android:paddingLeft">0dip</item>
    <item name="android:paddingRight">0dip</item>
</style>


<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/splash</item>
</style>

Bhuvanesh BS
  • 13,474
  • 12
  • 40
  • 66
Hussain
  • 55
  • 9
  • add your manifest and your style.xml file please – Pier Giorgio Misley Sep 07 '17 at 09:21
  • hi @PierGiorgioMisley thanks for your reply. I have added the manifest.xml and style.xml in the main ques. please check it there. – Hussain Sep 07 '17 at 09:34
  • ok, add also the XML code of the mainactivity (the one working correctly) and the one of another activity which is not working as expected. (you can avoid useless stuffs, just add the relevant part containing or interacting with the toolbar :) – Pier Giorgio Misley Sep 07 '17 at 09:44
  • my app_bar_main.xml using tag. from content main. app_bar_main contains this lines of code which is working fine. but all other layout doesn't have this code. – Hussain Sep 07 '17 at 09:50

2 Answers2

0

You can use <include> tag to achieve it. Just like this

<LinearLayout 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:orientation="vertical"
    tools:context="com.dzq.aprivate.view.activity.MainActivity">

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

    <FrameLayout
        android:id="@+id/lay_container"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp"/>

    <include layout="@layout/lay_main_bottom"/>
</LinearLayout>

Use <include layout="@layout/toolbar_header"/> in every Activity you want.

杜咸鱼
  • 19
  • 5
0

Ok, I have resolved the issue. The previous code was not working for other layouts because activity_main.xml was using toolbar instead of action bar, so i had to write another piece of style for the action bar. I added these style..

<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar.Solid">
    <item name="titleTextStyle">@style/MyTitleTextStyle</item>
</style>

<style name="MyTitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textSize">24sp</item>
</style>

and then added the item in AppTheme like this..

<item name="actionBarStyle">@style/MyActionBar</item>

and it's working fine now. Thanks everyone for replying.

Hussain
  • 55
  • 9