I am trying to change my background colour for my app and the actionBar to different colours:
<!-- Base application theme. -->
<style name="actionBar" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/veniceblue</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat">
<item name="android:background">#drawable/background_template</item>
<item name="actionBarTheme">#color/veniceblue</item>
</style>
But in my manifest file i add :
android:theme="#style/actionBar">
But I'm not sure how to add the background at the same time?
I do want it to be set for the whole application??
Excuse me if i didn't understand your question (i'm just a beginner trying to learn and help )
you can use android.support.v7.widget.Toolbar
layout.xml
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="#style/AppTheme.AppBarOverlay"
android:id="#+id/appBarLayout">
<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>
and style.xml
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="AppCompaTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/primaryColor</item>
<item name="colorPrimaryDark">#color/primaryColorDark</item>
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:windowNoTitle">true</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
Related
The code blocks in my activity_main.xml with the errors are as follows:
<EditText
style="#style/editText_style"
android:inputType="textEmailAddress"
android:id="#+id/editText1" />
<EditText
style="#style/editText_style"
android:inputType="textPassword"
android:id="#+id/editText2" />
The code in my styles are as follows:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- 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="editText_style">
<item name="android:gravity">center</item>
<item name="android:background">#drawable/editText_background</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
<item name="android:ems">10</item>
<item name="android:layout_margin">10dp</item>
</style>
</resources>
I'm getting the error stating:
The 'style' attribute is not declared.
I dont understand what is wrong. Any help appreciated. Thank you.
I just added drawerlayout in my app an changed the background color of toolbar,but drawerlayout button and menu icon are black , it should be white.
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="actionMenuTextColor">#color/font</item>
<item name="android:actionMenuTextColor">#color/font</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" />
</resources>
AppBarLayout:
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="35dp"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll" >
<com.miguelcatalan.materialsearchview.MaterialSearchView
android:id="#+id/search_view"
android:layout_width="30.0dip"
android:layout_height="match_parent"
/>
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="#color/tab_normal"
app:tabSelectedTextColor="#color/tab_se"
app:tabTextColor="#color/tab_normal"
/>
</android.support.design.widget.AppBarLayout>
And that is what app looks like:
Add a new style to change the color of hamburger icon and overflow menu icon.
To change Hamburger Icon color
<style name="DrawerArrowStyle" parent="#style/Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#android:color/white</item>
To change Overflow Menu Color
Add this item to your current style.
<item name="android:textColorSecondary">#android:color/white</item>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="color">#android:color/black</item>
</style>
<style name="MyMaterialTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowContentTransitions" tools:targetApi="lollipop">true</item>
<item name="android:windowAllowEnterTransitionOverlap" tools:targetApi="lollipop">true
</item>
<item name="android:windowAllowReturnTransitionOverlap" tools:targetApi="lollipop">true
</item>
<item name="android:windowSharedElementEnterTransition" tools:targetApi="lollipop">
#android:transition/move
</item>
<item name="android:windowSharedElementExitTransition" tools:targetApi="lollipop">
#android:transition/move
</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="android:statusBarColor">#color/white</item>
<item name="android:windowLightStatusBar">true</item>
</style>
I cannot find how to change the text color of the overview toolbar on Android.. :
I tried this one :
android:theme="#style/AppTheme"
<style name="AppBlankTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme" parent="AppBlankTheme">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">true</item>
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:textColorSecondary">#android:color/white</item>
</style>
I want to change the color of the title ("Sharezone") and the close button of the overview toolbar to white.
Thanks.
------------------------- EDIT -------------------------------------------
After a lot of failed solutions, here's my entire code :
style.xml
<style name="AppBlankTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme" parent="AppBlankTheme">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:textColorTertiary">#color/grey_300</item>
</style>
AndroidManifest.xml
<application
...
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
...
android:theme="#style/AppTheme">
</activity>
</application>
And here's the toolbar I use in Activity :
<android.support.v7.widget.Toolbar android:id="#+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary">
<TextView
android:id="#+id/toolbar_app_name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/app_name"
android:textSize="30sp"
android:gravity="center_horizontal|center_vertical"
android:textColor="#color/grey_300"/>
</android.support.v7.widget.Toolbar>
This is because of Theme.which you have set in your style
style name="AppBlankTheme" parent="Theme.AppCompat.Light.DarkActionBar"
please use this Theme
style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"
Now your App's dark theme will be removed
You can do that by XML, if your activity is called MainActivity go to the res/layout/activity_main, go to design and press/select the action bar, then to properties on the right and select titleTextColor and change tot he required colour.
Choose colour here:
#. Seems your themes are OK. In AndroidManifest.xml file, apply AppTheme to your desired Activity.
AndroidManifest.xml
<activity
android:name=".YourActivity"
android:theme="#style/AppTheme" />
#. If you are using Toolbar in your layout XML, then you can change its title color programmatically:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar)
toolbar.setTitleTextColor(Color.WHITE);
UPDATE:
As per your updated question, seems you are using custom Toolbar. To change title "Sharezone" color, you have to change the background color of TextView (toolbar_app_name).
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary">
<TextView
android:id="#+id/toolbar_app_name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/app_name"
android:textSize="30sp"
android:gravity="center_horizontal|center_vertical"
android:textColor="#FFFFFF"/>
</android.support.v7.widget.Toolbar>
Hope this will help~
style.xml
here i purposely disable action bar because i dont want it to appear on my splash screen
<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>
</style>
MainActivity.java
After that I want action bar exist in Main activity by using set supportactionbar, but the action bar doesnt work after I run the code, and whole process is without error, can someone tell me what's wrong with my code.
Toolbar tb;
tb = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(tb);
You have two options.
1: Manually add a Toolbar in your XML. Example:
<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">
</android.support.v7.widget.Toolbar>
</LinearLayout>
See https://guides.codepath.com/android/Using-the-App-Toolbar for more toolbar information.
OR
2: Create a new theme for your splash screen and set it in your manifest. Example:
<activity
android:name=".view.activity.SplashActivity"
android:theme="#style/Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
And then in your app's styles.xml:
<style name="Splash" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowFullscreen">true</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="android:windowBackground">#drawable/splash_screen</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Either one of these are fine, although personally I always keep a separate style for my splash screen just to keep things clean and simple.
I have a problem with a Toolbar (with TabLayout) during the scroll, as it also hides the notification bar, making it look the title of the toolbar.
Here the layout of the activity:
<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:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.testapp.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
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"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
How can i solve this? I've seen apps like Google Play or Phonograph not have this problem.
Thanks in advance.
Regards.
UPDATE
Here is my style.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</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" />
</resources>
And style.xml v21
<resources>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
</resources>
About the response of MML13 to remove fitsSystemWindows, it works, but the notification bar loses color, being white.
Try this.
Change this part.
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
To this.
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#color/colorPrimaryDark</item>
</style>
Hope this will help you.
Change
app:layout_scrollFlags="scroll|exituntilcollapse"
instead of
app:layout_scrollFlags="scroll|enterAlways"
remove:
android:fitsSystemWindows="true"
from CoordinatorLayout
you must use:
valuse style:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#673AB7</item>
<item name="colorPrimaryDark">#512DA8</item>
<item name="colorAccent">#FF4081</item>
</style>
values-v21:
<style name="Theme.DesignDemo" parent="AppTheme">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>