I'm trying to modify the text size of my ActionBar and I tried styling it but it doesn't change anything... That's my styles page.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/AppTheme.Styled.ActionBar.TitleTextStyle</item>
<!-- Customize your theme here. -->
</style>
<style name="AppTheme.ActionBar">
<item name="android:titleTextStyle">#style/AppTheme.Styled.ActionBar.TitleTextStyle</item>
</style>
<style name="AppTheme.Styled.ActionBar.TitleTextStyle" parent="#android:style/Widget.TextView">
<item name="android:textSize">19sp</item>
</style>
Also I had this on my styles.xml but doesn't work either
<style name="Theme.FixedSize" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="actionBarSize">4dip</item>
<item name="android:actionBarSize">4dip</item>
<item name="android:textSize">3sp</item>
</style>
I also have tried with a nasty way but it doesn't work only works with the color.
mActionBar.setTitle(Html.fromHtml("<font size=\"3\" color=\"white\">" + getString(R.string.app_name_device)));
After you say to me... I know now it's used Toolbar BUT I have to do it now with ActionBar.
EDIT
I hided the ActionBar like this :
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<!-- Customize your theme here. -->
</style>
Then I added a ToolBar like this :
<android.support.v7.widget.Toolbar
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="?actionBarSize"
android:id="#+id/toolbar"
app:titleTextAppearance="#style/Toolbar.TitleText" />
But the Layout messed up, it goes up and now the ToolBar is collapsed with the first TextView
You can do it programmatically like this
Html.fromHtml("<big><font color=\"white\">" + getString(R.string.app_name_device)+"</big>")
for small text you can change tag <big> with <small>
and if you want to provide specific size of Title Text then you should use Toolbar and use below theme/style
Create one layout toolbar.xml and put below code
<android.support.v7.widget.Toolbar
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="?actionBarSize"
android:id="#+id/toolbar"
app:titleTextAppearance="#style/Toolbar.TitleText" />
and change size in
<style name="Toolbar.TitleText" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">18sp</item>
</style>
and you can inculde above layout in your each Activity layout files like below
<include
layout="#layout/toolbar"
/>
Toolbar in your Activity
ToolBar mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setTitle(Html.fromHtml("<big><font color=\"white\">" + getString(R.string.app_name_device)+"</big>"));
I do it so:
import android.support.v7.app.ActionBar;
public void title_change(String text) {
TextView tv = new TextView(this);
tv.setText(text);
tv.setTextSize(15);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(tv);
}
Related
I am new to Android and working on my first android app. For my app I need a transparent Action Bar with a Navigation Drawer button. Everything is working fine except the color of the Action Bar. It is having blue color instead of transparent. I have tried various ways to make it transparent but its still blue. Can someone please help me out with my code:
custom_navigation_bar.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="#style/AppTheme.PopupOverlay"/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
styles.xml:
<resources>
<!-- Themes for Navigation Drawer -->
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay"
parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:background">#00000000</item>
</style>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light">
<item name="android:background">#00000000</item>
</style>
</resources>
Java Code Snippet:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//Setting Transparent Color for Action Bar
ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00000000")));
You can just set the toolbar background to transparent :
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#00000000"/>
you have one item in base theme windowActionBarOverlay set it to true and set action bar color to transparent.
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:textColorPrimary">#color/text_color</item>
<item name="colorPrimary">#android:color/transparent</item>
<item name="windowActionBarOverlay">true</item>
</style>
</resources>
I've got the following problem: I'm trying to achieve an app design like instagram, where most of the app is using a light theme. However, I haven't found a method of coloring the toolbars text and icon elements like navigation drawer and back-button black.
When using the following style.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#FAFAFA</item>
<item name="colorPrimaryDark">#BDBDBD</item>
<item name="colorAccent">#FF4081</item>
</style>
<style name="AppTheme" parent="AppTheme.Base"></style>
<style name="ToolbarTheme" parent="ThemeOverlay.AppCompat.ActionBar">
<!-- Used to for the title of the Toolbar -->
<item name="android:textColorPrimary">#color/black</item>
<!-- Used to for the title of the Toolbar when parent is Theme.AppCompat.Light -->
<item name="android:textColorPrimaryInverse">#color/black</item>
<!-- Used to color the text of the action menu icons -->
<item name="android:textColorSecondary">#color/black</item>
<!-- Used to color the overflow menu icon -->
<item name="actionMenuTextColor">#color/black</item>
</style>
</resources>
and this attribute for the toolbar:
android:theme="#style/ToolbarTheme"
it produces the following design:
As you can see, the navigation drawer is white and the tab titles are also white.
I also tried this style which would work fine but only if you don't explicitly set up a toolbar in your activity like this:
Activity Code:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Style.xml:
<!-- Base application theme. -->
<style name="AppTheme.Base" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
When using this style with no explicit toolbar, the design looks like I want, however, I can't call the toolbar this way. If you set up the toolbar with Theme.AppCompat.Light, it will throw an error.
Also note the difference between the two styles: Theme.AppCompat.Light vs Theme.AppCompat.Light.NoActionBar
Any ideas on how to do this?
I just went with the standard android themes now like this:
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/container"
android:theme="#style/ThemeOverlay.AppCompat.Light">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="enterAlways"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:titleTextColor="#color/black"/>
</android.support.design.widget.AppBarLayout>
This is far easier than trying to set your own style.
I have this code in my Activity:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
setTitle("My title");
In styles.xml, I have this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
//more stuff
</style>
<style name="Toolbar" parent="Theme.AppCompat">
<item name="android:textAppearance">#style/Toolbar.Text</item>
</style>
<style name="Toolbar.Text">
<item name="android:textColor">#android:color/white</item>
</style>
and the Toolbar layout:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:theme="#style/Toolbar" />
I want the toolbar's text to be white, but it is black. I have tried lot of things but I really can't change it.
Whatever it is, The issue is come from this line :
<style name="Toolbar" parent="Theme.AppCompat">
And this: app:theme="#style/Toolbar" (You've used app instead of android, Be careful about that)
And you don't really need to do that.
Just use this line for the Toolbar:
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
So:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/AppTheme" />
Then you should see the white text and etc
As you can see, I've set the app:popupTheme to AppTheme which the parameter is :
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
After adding that line to the Toolbar, Now you can remove these:
<style name="Toolbar" parent="Theme.AppCompat">
<item name="android:textAppearance">#style/Toolbar.Text</item>
</style>
<style name="Toolbar.Text">
<item name="android:textColor">#android:color/white</item>
</style>
Then the only thing you should do is setting the parent for app:popupTheme to this :
Theme.AppCompat.Light.NoActionBar
Which it can be your Activity style parent.
That's it :)
Use the editor for this. Go to tools->android->theme editor. There you can find the option for changing the colors.
you may be using SDK less than 23 you can try this
In xml :-
android:titleTextColor="#color/colorPrimary"
In fragment
toolbar.setTitleTextColor(Color.RED);
I want to set background of toolbar transparent.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:theme="#style/ThemeOverlay.AppCompat.Dark"
android:elevation="4dp"
android:id="#+id/tool_bar_org"
android:paddingTop="0dp">
</android.support.v7.widget.Toolbar>
Here is my toolbar layout background is not being transparent
just show in white color
toolbar = (Toolbar) findViewById(R.id.tool_bar_org);
toolbar.getbackgroud().setAlpha(0);
setSupportActionBar(toolbar);
Its not working. Can you please tell me how to make it transparent.
This is the theme I have used in my project to make the appCompact ActionBar as transparent, modify it according to your needs:
<style name="adhoctheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/adhocblack</item>
<item name="actionBarStyle">#style/adhocblack</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
</style>
<style name="adhocblack" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#0D000000</item>
<item name="background">#color/appcompact_transparent_actionbar_bg</item>
<item name="android:icon">#drawable/logo_header_2</item>
</style>
Where appcompact_transparent_actionbar_bg = #0D000000
Important:
Have a look here to check how different values folders contain specific style files to render on various API's
I am currently implement toolbar into my code and having some issues with it. It does not display or change the colour of the status and bar background. Here is the code I wrote:
toolbar.xml
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/my_awesome_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize" />
styles.xml
<resources>
<!-- Application theme. -->
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light">
<item name="windowActionBar">false</item>
<item name="colorPrimary">#color/blue</item>
<item name="colorPrimaryDark">#color/blue</item>
</style>
<color name="blue">#3F51B5 </color>
</resources>
java file
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_warfarin_info);
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
if (toolbar != null) {
setSupportActionBar(toolbar);
}
}
Result
May I know what did I do wrong? Thanks..
Firstly, in the toolbar layout XML file, you havent linked the style to the View. Try adding this line:
style="#style/AppTheme.NoActionBar"
ie:
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/my_awesome_toolbar"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:minHeight="?attr/actionBarSize"
style="#style/AppTheme.NoActionBar"
>
And the styles XML file:
<resources>
<!-- Application theme. -->
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light">
<item name="windowActionBar">false</item>
<item name="android:background">#color/blue</item>
</style>
<color name="blue">#3F51B5 </color>
</resources>