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>
Related
I am learning how to implement Dark Theme to application.
After reading documents from this, below are the requirements that I understand
make sure "Style" parent = <style name="AppTheme" parent="Theme.AppCompat.DayNight">
create a new colors for Dark Theme in side colors.xml file
if using "Switch" toggle, use AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); and AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); inside onCheckedChanged listener
Based on testing, calling AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); will trigger recreate() to recreate the activity, result it will change the theme as expected, also the BLACK blinking thingy will appear.
After reading through this, it stated that I need to declare setTheme method before setContentView(R.layout.activity_main); so it will solve the BLACK thingy issue.
The Android Dev document does not mentioned anything about setTheme is required in OnCreate method after AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); is used
If using only AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); able to switch desire theme, what's the point of using setTheme again in onCreate method?
Is the BLACK blinking thing a bug? or is there a proper way to solve it?
~~~~~~~~~~~~~~~~~~~~~~~~~~~ UPDATE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Maybe my questions is confusing as well. To make it short, just wanted to know that why "setTheme" is needed to declared in `onCreate` when `AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)` already restarted the acitivy?
I'm so confused and spent more than a week to solve this, guidance or tips are much appreciated
The AppCompactDelegate some times recreates the activity that causes black blinking
Check This It Changes theme without black blinking
Create two themes or use default dark theme xml like this :
<!-- Dark theme -->
<style name="DarkTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/darkColorPrimary</item>
<item name="colorPrimaryDark">#color/darkColorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="fontFamily">#font/roboto</item>
<item name="listBackground">#color/darkListBackground</item>
<item name="cardBackground">#color/darkCardBackground</item>
<item name="textColor">#color/darkCardTitle</item>
<item name="actionBarBackgroundColor">#color/darkColorPrimary</item>
<item name="actionBarTextColor">#color/darkCardTitle</item>
<item name="dialogTextColor">#color/darkDialogTitle</item>
<item name="dialogDateColor">#color/dialogDateColor</item>
</style>
<!-- Light theme -->
<style name="LightTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/lightColorPrimary</item>
<item name="colorPrimaryDark">#color/lightColorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="fontFamily">#font/roboto</item>
<item name="listBackground">#color/lightListBackground</item>
<item name="cardBackground">#color/lightCardBackground</item>
<item name="textColor">#color/lightCardTitle</item>
<item name="actionBarBackgroundColor">#color/lightColorPrimary</item>
<item name="dialogTextColor">#color/lightDialogTitle</item>
<item name="dialogDateColor">#color/dialogDateColor</item>
</style>
Use Shared Prefrence to save themes type
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("NightMode", false);
editor.apply();
Change App theme on Activity on create method using shared prefrence
if (!darktheme) {
setTheme(R.style.DarkTheme);
} else {
setTheme(R.style.LightTheme);
}
For Brief Information get that project :
https://github.com/yeshasmp/ToDo/tree/v1.0
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 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"
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 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.