I am using android studio 3.0 and want to make actionbar transparent with activity's background.I just read all the questions about it but that doesen't work for me.help me guys.
minSdkVersion 20
targetSdkVersion 26
here is my style.xml code
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:background">#android:color/transparent</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>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" >
</style>
Like This
Try this theme to make your Actionbar transparent
<style name="AppTheme.ActionBar.Transparent2" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBarOverlay">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="colorPrimary">#android:color/transparent</item>
<item name="colorPrimaryDark">#android:color/transparent</item>
<item name="colorAccent">#android:color/transparent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:homeAsUpIndicator">#mipmap/ic_left_back</item>
</style>
Related
I created an android application and when I downloaded it to my phone it appeared in dark mode.
I want my application to always be in light mode so I used the following:
super.onCreate(savedInstanceState);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
But it still showed me the app in dark mode.
How can I completely disable it?
My styles.xml file is:
<style name="CustomActivityTheme" parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="android:windowActionBarOverlay">true</item>
<!-- other activity and action bar styles here -->
</style>
<!-- style for the action bar backgrounds -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="android:background">#color/colorGraySearchText</item>
<item name="background">#color/colorGraySearch</item>
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="android:subtitleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="subtitleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<!-- Text -->
<style name="MyTheme.ActionBar.TitleTextStyle" parent="#android:style/TextAppearance">
<item name="android:textColor">#color/colorGraySearchText</item>
<item name="android:textSize">16dp</item>
</style>
<style name="CustomActivityTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="CustomActivityTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="CustomActivityTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
SOLUTION:
The following steps solved my problem:
Changing in my build.gradle (app) to :
compileSdkVersion 29
targetSdkVersion 29
adding the following line to any style in my style.xml:
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
Thank you
I want to make the ActionBar transparent throughout the app and also change the text colour to white in the ActionBar. I tried setting the android:background to null but it had no effect. I am still getting a white ActionBar with Black text in the following code:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/app_white</item>
<!--item name="colorPrimaryDark">#color/colorPrimaryDark</item-->
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<!--item name="colorAccent">#color/colorAccent</item-->
<item name="colorAccent">#1da1f2</item>
<!-- <item name="actionBarStyle">#style/MyActionBar</item>-->
<!-- <item name="android:actionBarStyle">#style/MyActionBar</item>-->
</style>
<style name="MyActionBar" parent="#android:style/Widget.ActionBar">
<item name="android:background">#null</item>
<item name="background">#null</item>
<item name="fontFamily">#font/mukta_bold</item>
<item name="titleTextStyle">#style/MyActionBarTitle</item>
<item name="actionMenuTextColor">#color/app_white</item>
</style>
<!-- <style name="MyActionBar.MenuTextStyle"-->
<!-- parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">-->
<!-- <item name="android:textColor">#color/app_light_black</item>-->
<!-- </style>-->
<style name="MyActionBarTitle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/app_white</item>
</style>
<style name="Switch_Style">
<item name="android:textColor">#000000</item>
<item name="android:textSize">15sp</item>
<item name="android:textStyle">bold</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="CustomTheme" parent="Theme.MaterialComponents.Light.NoActionBar"/>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.MaterialComponents.Light" />
<style name="Widget.MyApp.MyButton" parent="Widget.MaterialComponents.Button">
<item name="backgroundTint">?attr/colorSecondary</item>
</style>
</resources>
You should use colorControlNormal flag in your Theme for AppBar
<style name="appBarTheme" parent="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="colorControlNormal">#android:color/white</item>
<item name="android:textColorPrimary">#android:color/white</item>
</style>
and in your AppBarLayout use background as transparent
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:theme="#style/appBarTheme">
...........
</com.google.android.material.appbar.AppBarLayout
Make your BaseTheme of app as NoActionBar so you can create a custom action bar in your activity/fragment -
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
Happy Coding !!
I am using Material Design in my Android app and I want to change Actionbar text color and back button color.
This code is not working:
<style name="AppTheme" parent="Theme.MaterialComponents.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="android:windowContentOverlay">#null</item>
<!--<item name="android:textSize">3sp</item>-->
<item name="android:actionBarStyle">#style/MyTheme.ActionBarStyle</item>
</style>
<style name="MyTheme.ActionBarStyle" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/titleColor</item>
</style>
Using the ActionBar in your theme you can use:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<item name="actionBarTheme">#style/ThemeOverlay.Actionbar</item>
</style>
<style name="ThemeOverlay.Actionbar" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar" >
<item name="android:textColorPrimary">#color/....</item>
</style>
I'm following the Android Documentation and have correctly copied this code:
<resources>
<style name="CustomTheme"
parent="Base.Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionMenuTextColor">#color/actionbar_text</item>
</style>
<style name="MyActionBar"
parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#color/background</item>
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<style name="MyActionBarTitleText"
parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/actionbar_text</item>
</style>
</resources>
I've set the activities manifest to "CustomTheme" and have the right information in strings.xml so I don't see what the problem would be. Any help would be appreciated. Thanks.
Try removing the android: tag and also, you have to set the Parent ActionBar to AppCompat's ActionBar.
<style name="CustomTheme"
parent="Base.Theme.AppCompat.Light">
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionMenuTextColor">#color/actionbar_text</item>
</style>
<style name="MyActionBar"
parent="Base.Widget.AppCompat.ActionBar">
<item name="background">#color/background</item>
<item name="titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<style name="MyActionBarTitleText"
parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/actionbar_text</item>
</style>
Option Menu show incorrectly on Custom Style map
The problem raised on an application in android
I have a custom theme on my app. The problem is that the option menu shows incorrectly ,so the option menu shows cut of on the screen.
I wondering why could happen?
This is my style file xml
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:typeface">normal</item>
<item name="android:typeface">sans</item>
<item name="android:typeface">serif</item>
<item name="android:typeface">monospace</item>
<item name="android:actionBarItemBackground">#drawable/selectable_background_example</item>
<item name="android:popupMenuStyle">#style/PopupMenu.Example</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.Example</item>
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle.Example</item>
<item name="android:actionDropDownStyle">#style/DropDownNav.Example</item>
<item name="android:actionBarStyle">#style/ActionBar.Solid.Example</item>
<item name="android:actionModeBackground">#drawable/cab_background_top_example</item>
<item name="android:actionModeSplitBackground">#drawable/cab_background_bottom_example</item>
<item name="android:actionModeCloseButtonStyle">#style/ActionButton.CloseMode.Example</item>
</style>
<style name="ActionBar.Solid.Example" parent="#android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:background">#drawable/ab_solid_example</item>
<item name="android:backgroundStacked">#drawable/ab_stacked_solid_example</item>
<item name="android:backgroundSplit">#drawable/ab_bottom_solid_example</item>
<item name="android:progressBarStyle">#style/ProgressBar.Example</item>
</style>
<style name="ActionBar.Transparent.Example" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/ab_transparent_example</item>
<item name="android:progressBarStyle">#style/ProgressBar.Example</item>
</style>
<style name="PopupMenu.Example" parent="#android:style/Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_example</item>
</style>
<style name="DropDownListView.Example" parent="#android:style/Widget.Holo.Light.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background_example</item>
</style>
<style name="ActionBarTabStyle.Example" parent="#android:style/Widget.Holo.Light.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator_ab_example</item>
</style>
<style name="DropDownNav.Example" parent="#android:style/Widget.Holo.Light.Spinner">
<item name="android:background">#drawable/spinner_background_ab_example</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel_example</item>
<item name="android:dropDownSelector">#drawable/selectable_background_example</item>
</style>
<style name="ProgressBar.Example" parent="#android:style/Widget.Holo.Light.ProgressBar.Horizontal">
<item name="android:progressDrawable">#drawable/progress_horizontal_example</item>
</style>
<style name="ActionButton.CloseMode.Example" parent="#android:style/Widget.Holo.Light.ActionButton.CloseMode">
<item name="android:background">#drawable/btn_cab_done_example</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Example.Widget" parent="#android:style/Theme.Holo">
<item name="android:popupMenuStyle">#style/PopupMenu.Example</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.Example</item>
</style>
For any ones that have this same trouble, the solution , in my case , was solved by added this line in the manifest file.
<supports-screens
android:anyDensity="true" />