I'm having trouble with android app.
I try to make my action bar transparent (like google maps or google play music) but instead of becoming transparent it becomes white.
Here is my custom theme:
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:windowActionBarOverlay">true</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
<item name="android:background">#android:color/transparent</item>
<item name="android:logo">#android:color/transparent</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#FFFFFF</item>
</style>
Has anyone got any ideas why is that happening ?
EDIT 1:
I forgot to mention that I'm using fragments. So I have only one activity with Navigation Drawer and a fragment inside. The fragment itself contains a listview.
Thank you all in advance !
You can try the answer in this thread: Transparent Actionbar: custom tabcolor
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#330000ff")));
actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#550000ff")));
The one changes the color of the ActionBar and the other the color of the tabs attached to it.
If you want to make it completely transperant then your first number of the color should be 00: #00123456, because the colors are in the (Alpha, Red, Green, Blue) schema.
Related
In Android, is there any way to give an ActionMode the same appearance as the normal Toolbar? Currently my ActionMode looks different to the Toolbar in that the background is slightly brighter (at least using Theme.AppCompat.NoActionBar), the MenuItems are fully black/white (depending on the theme) instead of colorControlNormal (which I set them to) and most annoyingly, there is an underline under the ActionMode that I can't seem to get rid of. Instead, I'm trying to make the ActionMode indistinguishable from the Toolbar.
The Toolbar (also what the ActionMode is meant to look like):
What the ActionMode currently looks like:
Any help would be highly appreciated!
For changing the background color of ActionMode & Remove the bottom line. You can use actionModeStyle where you can set background to your desired color.
For changing the icon color you can set colorControlNormal inside the actionBarTheme.
So your theme would look like this:
<style name="Theme.AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<!--add this-->
<item name="actionModeStyle">#style/ActionModeStyle</item>
<item name="actionBarTheme">#style/MyActionBarTheme</item>
</style>
<style name="MyActionBarTheme" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
//replace with your own desired color
<item name="colorControlNormal">#a00</item>
</style>
<style name="ActionModeStyle" parent="#style/Widget.AppCompat.ActionMode">
//replace with your own desired color
<item name="background">#color/colorPrimary</item>
<item name="titleTextStyle">#style/ActionModeTitleTextStyle</item>
</style>
<style name="ActionModeTitleTextStyle" parent="#style/TextAppearance.AppCompat.Widget.ActionMode.Title">
//replace with your own desired color
<item name="android:textColor">#a00</item>
</style>
Within the ActionBar, I am trying to left align the logo and also display the Activity title. I'm finding it difficult to left align the logo.... and also display the logo and the title together.
My Activity is extending AppCompatActivity. I am using the styles.xml to provide the theme to the app. In the styles.xml theme, I have the following:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">#style/ActionBarLogoTheme</item>
</style>
Which calls the following:
<style name="ActionBarLogoTheme" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="logo">#drawable/logo</item>
<item name="displayOptions">useLogo|showHome|showTitle</item>>
<item name="android:layout_gravity">left</item>
<item name="android:gravity">left</item>
</style>
In the above, the 'gravity' and 'layout_gravity' don't seem to take affect, and also the 'showTitle' display option doesn't seem to take affect also. Would anyone be able to help. The following illustrates what it currently looks like, and what I would like it to look like.
Thank you all.
If you want to use an ActionBar you can use:
<style name="ActionBar" parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="displayOptions">showHome|useLogo|showTitle</item>
<item name="logo">#drawable/....</item>
</style>
You can also it programmatically:
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayUseLogoEnabled(true);
getSupportActionBar().setLogo(R.drawable....);
getSupportActionBar().setTitle("Title");
But you can also use a Toolbar:
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setNavigationIcon(R.drawable.ic_menu_camera);
setSupportActionBar(toolbar);
I'm trying to change some colors of the components of my application by setting a custom theme for day mode and night mode, like this:
in values/styles.xml (day mode):
<resources>
<!-- Base application theme. -->
<style name="MyTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
...
</resources>
Same file in values/styles.xml (night)
I want to change the color of some parts of the UI (seekbar bar, toolbar, action bar title, floating buttons etc.) but I don't know which color corresponds to each element and I'm kinda going crazy googling here and there for tricky solutions for any component I need to change the color too. Is there any guideline or good visual example on where to check all of this? For instance, right now it's taking a long time for me to figure out how to change the popupmenu background or the actionbar menu background since there's no attributes in the menu files. I'm new to android development so any kind of guidance regarding this would be very welcomed.
You used Theme.MaterialComponents.DayNight.... where DayNight is more of a adaptive dynamic theme which changes to material design default color. If you need more control to color and styles, do as follows:
Your Day theme inside values/styles.xml should extend from Theme.MaterialComponents.Light.DarkActionBar
Your Night theme inside values-night/styles.xml should extend from Theme.MaterialComponents as it is well-suited for the Dark Mode.
I want to change the color of some parts of the UI (seekbar bar, toolbar, action bar title, floating buttons etc.)
Regarding this, if you want app-wide changes then you can follow this method of styling(almost all views styling can be done this way):
<resources>
<!-- Base application theme. -->
<style name="MyTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="seekBarStyle">#style/MySeekBarStyle</item>
<item name="toolbarStyle">#style/MyToolBarStyle</item>
<item name="actionBarStyle">#style/MyActionBarStyle</item>
<item name="floatingActionButtonStyle">#MyFloatingActionButtonStyle</item>
<!-- a sample toolbar styling, choose parent with care -->
<!-- your AppTheme inheriting from MaterialComponents but toolbar
<!-- inheriting from platform theme-->
<!-- may case weird visual effects-->
<style name="MyToolBarStyle" parent="Widget.MaterialComponents.Toolbar">
<item name="titleTextColor">#color/lightWhite</item>
<item name="subtitleTextColor">#color/lightWhite</item>
</style>
</resources>
If you want to style each for eg. ToolBar differently, you can use style="#style/MyToolBarStyle" attributes in your layout files to give each of them different shape, colour and other material effects as you want.
About Colors:
Normally, you can play with these colour attributes in your styles.xml to change the complete look and feel of your app.
<!-- primary colour of your brand and its variants -->
<item name="colorPrimary">#color/colorPrimary700</item>
<item name="colorPrimaryDark">#color/colorPrimary900</item>
<item name="colorPrimaryVariant">#color/colorPrimary500</item>
<!-- colour which contrasts from your primary colour -->
<item name="colorAccent">#color/colorAccent</item>
<!--secondary colour of your brand and its variants -->
<item name="colorSecondary">#color/colorSecondary700</item>
<item name="colorSecondaryVariant">#color/colorSecondary500</item>
<!--background color for your root layout file -->
<item name="android:colorBackground">#android:color/white</item>
<!--background color of children view -->
<item name="colorSurface">#color/lightWhite</item>
<!--color to show error mostly it will be red or orange
<item name="colorError">#color/colorErrorAlternate</item>
<!-- These are colors which constrasts colors defined for -->
<!-- primary, secondary, bg, surface, error respectively. -->
<!-- For eg: TextViews in Toolbar colored with colorPrimary -->
<!-- will use colorOnPrimary as their text color -->
<item name="colorOnPrimary">#color/lightWhite</item>
<item name="colorOnSecondary">#color/lightDark</item>
<item name="colorOnBackground">#color/lightDark</item>
<item name="colorOnSurface">#color/lightDark</item>
<item name="colorOnError">#color/lightDark</item>
Important Links:
Official Material Design guide for designing dark theme
Official Material Design guide for developing dark theme
Using switchpreference to switch theme
Nick Butcher's Medium Blog : you will know more about colours here
I have defined a relativeLayout with a recyclerView and an imageView. I want the imageView to draw behind the status bar. But for some reason
android:fitsSystemWindow = true
doesn't work.
How can I achieve it?
Set your full-screen theme like following
<style name="Theme.MyApp.FullScreen" parent="Theme.MyApp">
<item name="android:statusBarColor" tools:targetApi="lollipop">#android:color/transparent</item>
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
<item name="android:windowDrawsSystemBarBackgrounds" tools:targetApi="lollipop">true</item>
</style>
Don't add android:fitsSystemWindows="true" in your layout file
Also, no need to add android:windowSoftInputMode="adjustPan" in Manifest file
To draw behind status bar, You have to set your status bar have transparent background.
So, you need to set this with adding below proprieties in your theme:
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
And in your .xml you have already set below property which is useful:
android:fitsSystemWindows="true"
How can I change the color/transparency of the Navigation Bar from black to a generic color in pre-Lollipop devices (e.g. the color of the status bar or of the action bar)?
Can I do it using AppCompat or is it only possible for SDK 21?
You can set the attribute navigationBarColor in an AppCompat theme, or android:navigationBarColor in a native v21 theme.
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
...
<item name="navigationBarColor">#123456</item>
</style>
https://developer.android.com/training/material/theme.html#StatusBar
Note that this does not work on Pre-Lollipop devices, since this feature needs to be supported by the system, which is not the case on Android 4.4 or older.
Another programmatically way:
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(getResources().getColor(R.color.DarkOrange));
window.setNavigationBarColor(getResources().getColor(R.color.red));
Further, to change your status bar color, add the following line:
window.setStatusBarColor(getResources().getColor(R.color.green));
style-v21
<resources>
<style name="Theme.DesignDemo" parent="Base.Theme.DesignDemo">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentNavigation">true</item>//translucent
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:navigationBarColor">#android:color/transparent</item>
</style>