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"
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>
TL;DR;
How to remove the below unwanted white area?
I tried to change my theme which extends "Theme.AppCompat.Light.NoActionBar" and added my own customization.
After using the theme, all "pop-up" buttons have an extra white background like above screenshot:
How to remove those extra white area?
What xml attributes are controlling this?
styles.xml
<style name="MyCustomTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/accent</item>
<item name="android:textColorSecondary">#color/secondary_text</item>
<item name="android:alertDialogTheme">#style/CustomAppCompatAlertDialogStyle</item>
<item name="android:actionBarStyle">#style/CustomActionBarStyle</item>
</style>
I am trying to change all of my activities' background color from white to black. I have tried everything - changing windowBackground, colorBackground, background but nothing seems to be working and I know my style is working because if I changed primary, accent colors they seem to be changing. The background tag only changes the action bar's color. Here's my code for the theme (what I have so far) -
<style name="Yoyo" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent1</item>
<item name="android:windowBackground">#color/darkBackground</item>
<item name="android:colorBackground">#color/darkBackground</item>
<item name="android:textColor">#ffffff</item>
</style>
darkBackground is black - what I need for my app to show but its not showing.
Also, I have already tried using #drawable/my_drawable_file (in which I set black color) in windowBackground but even that doesn't work.
min sdk version - 21, target sdk version - 25
Try to change background your activity root element. For example:
<RelativeLayout 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:background="your_color">
Try:
<color name="custom_theme_color">#000000</color>
<style name="CustomTheme"Parent="android:Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowBackground">#color/custom_theme_color</item>
<item name="android:colorBackground">#color/custom_theme_color</item>
</style>
and then use the custom theme in your manifest
Nevermind people, I was just being stupid, I had hard-coded the colour for the said activity in the XML file, as soon as I removed the line which was setting the colour from XML the windowBackground started working!
I would really like to know if I am able to change the text color of the Appbar text in the PlacePicker API for Android. It should inherit the styling from my application, but it does not do that.
my styles.xml is as follows:
<style name="MaterialParent" parent="Theme.AppCompat.Light.NoActionBar">
<!-- ...and here we setting appcompat’s color theming attrs -->
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/accent</item>
<item name="android:textColor">#android:color/white</item>
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:textColorSecondary">#color/secondary_text</item>
<item name="icon">#color/icons</item>
<item name="divider">#color/divider</item>
<item name="colorControlHighlight">#color/accent_alpha26</item>
</style>
<style name="Material" parent="MaterialParent"/>
I've already tried changing android:textColorPrimary, android:textColorSecondary and textColor to white with no luck.
Please use Theme.AppCompat.Light.NoActionBar instade of Theme.AppCompat.Light.DarkActionBar
Just change the colorPrimary value of color file with the color hex code, that you want and it works fine.
I'm trying to change the style of a Button when someone clicks on it. I want to change both the background as the text colour. However, only the text color is changed. From that I conclude that the style is changed, but for some reason the background can't be overwritten.
I'm using this code in the onClick handler:
Button send_button = (Button) findViewById(R.id.button1);
send_button.setTextAppearance(context, R.style.activeButtonTheme);
The relevant styles in my styles.xml are:
<style name="buttonTheme">
<item name="android:background">#color/white</item>
<item name="android:textColor">#color/orange</item>
<item name="android:paddingTop">6dp</item>
<item name="android:paddingBottom">6dp</item>
<item name="android:layout_margin">2dp</item>
</style>
<style name="activeButtonTheme" parent="#style/buttonTheme">
<item name="android:background">#color/orange</item>
<item name="android:textColor">#color/white</item>
</style>
What's the problem here?
I do not want to set the background color from Java, I only want to change the style in Java.
Use selector for that purpose. Check this link for details(Custom background section) Regarding to your code, define appropriate selector.xml file in your resources directory, something like that:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/drawable_for_dissabled_button" android:state_enabled="false"/>
<item android:drawable="#drawable/drawable_for_pressed_button" android:state_enabled="true" android:state_pressed="true"/>
<item android:drawable="#drawable/drawable_for_enabled_button" android:state_enabled="true" android:state_focused="true"/>
<item android:drawable="#drawable/drawable_for_enabled_button" android:state_enabled="true"/>
</selector>
Assign just created selector to the button in the layout file:
<Button android:id="#+id/your_button_id"
android:background="#drawable/selector" />