To have a transluscent background for an android activity? - android

I wish to have a transluscent background for an activity, so that the previous activity can be seen beneath this activity. Something like a transluscent menu that pops up over a videa being played in the background.
Is this possible? Can you tell me how?
Note:I cannot use the default transluscent theme from android, since I am using my own customised background and theme for my application.
Pls help. Below is my style.xml wherein my_btn and my_list are selectors :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="btnstyle" parent="#android:style/Widget.Button">
<item name="android:textColor">#FFFFFF</item>
<item name="android:background">#drawable/my_btn</item>
</style>
<style name="liststyle" parent="#android:style/Widget.ListView">
<item name="android:listSelector">#drawable/my_list</item>
</style>
<style name="theme" parent="android:Theme.Translucent">
<item name="android:windowBackground">#drawable/background</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:buttonStyle">#style/btnstyle</item>
<item name="android:listViewStyle">#style/liststyle</item>
</style>
</resources>

Apply Translucent theme to your activity in AndroidManifest.xml
<activity android:theme="#android:style/Theme.Translucent">

Related

How to set the background colour of a Popup menu?

Hey everyone I am dealing with a small problem with Popup menu. Honestly I dont know where is the problem, I tried to search the internet if I can find any answers but unfortunatelly I cant. So..
I created a custom toolbar and set the activity to no actionbar. Then I created a popUp menu in this toolbar. First I tried to change the icon of a menu via styles and it worked. But then I wanted to change the background and text color of a menu items.
This is the code I have in my design tab of the menu item:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/fitItem1"
android:title="Item 1"
app:showAsAction="never" />
<item android:id="#+id/fitItem2"
android:title="Item 2"
app:showAsAction="never"/>
<item android:id="#+id/fitItem3"
android:title="Item 3"
app:showAsAction="never"/>
And even in the design menu it looked like this:
But when you start the app it looks by default (white background, black text)
So I thought that is it set somewhere in styles but there is nothing like that and every guide I tried to follow had no effect. Except style name="MyPopBackground" which actully changes the background.
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:actionOverflowButtonStyle">#style/MyActionButtonOverflow</item>
<item name="android:itemTextAppearance">#style/MyApp.PopupMenu</item>
<item name="android:popupBackground">#style/MyPopBackground</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="MyActionButtonOverflow" parent="android:Widget.Holo.Light.ActionButton.Overflow">
<item name="android:src">#drawable/triple_dot_icon</item>
</style>
<style name="MyApp.PopupMenu" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/colorLightGrey</item>
</style>
<style name="MyPopBackground" parent="android:style/Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">#color/colorGrey</item>
</style>
</resources>
There might be some useless styles but since I didnt know where is the prob. I left them there. My goal is to make that menu look like that one the image showed before.
I would be glad for any help, thanks for help.
Add popupMenu style to your AppTheme
<style name="AppTheme" parent="android:Theme.Light">
<item name="android:popupMenuStyle">#style/PopupMenu</item>
</style>
<style name="PopupMenu" parent="#android:style/Widget.PopupMenu">
<item name="android:popupBackground">#android:color/white</item>
</style>
then at mainifest.xml
<application
android:theme="#style/AppTheme" >
</application>
In style AppTheme, You add <item name="android:itemBackground">#color/colorMenu</item>

Is there a way to style PreferenceFragmentCompat

The title says it all: how can I style my PreferenceFragmentCompat. My v14/style.xml is
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:editTextStyle">#style/Widget.EditText.White</item>
<item name="preferenceTheme">#style/PreferenceThemeOverlay</item>
</style>
<style name="Widget.EditText.White" parent="#android:style/Widget.EditText">
<item name="android:textColor">#ffffffff</item>
</style>
</resources>
The base theme has a black background - the preferences screen is then unreadable as I have black text on that black background.
I've tried many things but I cannot change the text colour.
What I've had to do is to set the fragment container background colour to white whilst the settings fragment is active. An ugly hack and not what I want to have to do.
To answer my own question: my v14/style.xml is now
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:editTextStyle">#style/Widget.EditText.White</item>
<item name="preferenceTheme">#style/PreferenceThemeOverlay.v14.Material</item>
</style>
<style name="Widget.EditText.White" parent="#android:style/Widget.EditText">
<item name="android:textColor">#ffffffff</item>
</style>
<style name="PreferenceThemeOverlay.v14">
<item name="android:background">#color/settings_background</item>
<item name="android:textColor">#color/settings_text_colour</item>
<item name="android:textColorSecondary">#color/settings_text_colour_secondary</item>
</style>
</resources>
My problem is now to style a ListPreference.
Why is this so hard? If there is any documentation relating to styling preferences, it is well hidden. Grrrrrr!
Take a look at README for github project
Gericop/Android-Support-Preference-V7-Fix

ActionMode background not working on lollipop devices

Am trying to change the background color of the contextual action bar.
I did it in the following manner
v21/themes.xml & themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionModeOverlay">true</item>
<item name="actionModeStyle">#style/Widget.ActionMode</item>
<item name="android:actionModeStyle">#style/Widget.ActionMode</item>
</style>
</resources>
styles.xml
<style name="Widget.ActionMode" parent="#style/Widget.AppCompat.ActionMode">
<item name="background">#color/highlight_green</item>
</style>
The background color works fine in pre-lollipop devices. But does not work in lollipop.
Note: Tried adding
<item name="android:actionModeBackground">#color/highlight_green</item>
<item name="actionModeBackground">#color/highlight_green</item>
as well. But did not work.
Had the same problem since last library update, and adding the "actionModeBackground" item in my theme solved it.
Are you sure you are adding it under MyTheme, and not under Widget.ActionMode ?
Try only the next code:
Styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionModeStyle">#style/ActionMode</item>
</style>
<style name="ActionMode" parent="Widget.AppCompat.ActionMode">
<item name="background">#color/color_bar</item>
<item name="backgroundSplit">#color/color_bar</item>
</style>

Android: Set custom background color for layout using custom theme

i generated custom theme for my app on:
http://jgilfelt.github.io/android-actionbarstylegenerator/
And now i would like to add custom color for background of all activities ale fragments in the app.
I tried to do by this way, but it colors also backgroud of text views and images too (which i don't need).
How can i do it to avoid set custom background of the each activity or fragment layout ?
Thanks for any advice
<style name="Theme.Custom" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarItemBackground">#drawable/selectable_background_custom</item>
<item name="android:popupMenuStyle">#style/PopupMenu.Custom</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.Custom</item>
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle.Custom</item>
<item name="android:actionDropDownStyle">#style/DropDownNav.Custom</item>
<item name="android:actionBarStyle">#style/ActionBar.Solid.Custom</item>
<item name="android:actionModeBackground">#drawable/cab_background_top_custom</item>
<item name="android:actionModeSplitBackground">#drawable/cab_background_bottom_custom</item>
<item name="android:actionModeCloseButtonStyle">#style/ActionButton.CloseMode.Custom</item>
<item name="android:background">#color/custom_white</item>
<!-- Light.DarkActionBar specific -->
<item name="android:actionBarWidgetTheme">#style/Theme.Custom.Widget</item>
</style>
You can try adding windowBackground item to your theme, this should color all your activities' backgrounds.
<resources>
<style name="MyTheme" parent="#android:style/Theme.Light">
<item name="android:windowBackground">#color/background</item>
</style>
</resources>

Transparent Background

How can i make the background 50% transparent?
Let's say the background of an AbsoluteLayout so it's dark but you can still see through it?
You could apply a transparent theme to the required activity. Create a new style in /res/values/style.xml
<resources>
<style name="Transparent">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Translucent</item>
<item name ="android:windowBackground">#color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:colorForeground">#fff</item>
</style>
</resources>
The value of transparent is
<color name="transparent">#00000000</color>
Now in AndroidManifest.xml declare the theme of the activity to the one you just created.
<activity android:name="MyActivity" android:theme="#style/Transparent"></activity>

Categories

Resources