Transparent Background to an android activity class - android

I am creating an activity and adding views to it dynamically. This activity contains an imageview and a close button. I want the background of the image which is in fact the relative layout background to be transparent so that the icons on the home screen of the device could be visible.
I have tried
Window window = this.getWindow();
window.setBackgroundDrawable(newColorDrawable(android.graphics.Color.TRANSPARENT));
and also
relativeLayout.setBackgroundColor(Color.parseColor("#00000000"));
and this as well
relativeLayout.setBackgroundColor(0x00000000);
Nothing seems to work. Any pointers will be appreciated. Thanks.

you can create theme and use it for activity
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
<activity android:name=".SampleActivity" android:theme="#style/Theme.Transparent"/>

Define style theme for particular Activity.
In style.xml file
<style name="DialogTheme" parent="android:Theme.Holo.Light.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">#null</item>
</style>
And associate this style in Manifest with activity
<activity
android:name="com.pac.activity.YOURACTIVITY"
android:screenOrientation="portrait"
android:theme="#style/DialogTheme" >
</activity>

Hi use this link http://angrytools.com/android/button/. its help for you

Set the
android:background="#android:color/transparent"
Also the colour hexa you are using is wrong...
00000000 is hexa for non transparent white
Use
Ff000000 instead
In the top most viewgroup you have. This will essentially create a background with transparent colour on which other views will lie.
You can adjust transparency using other colours in that place.

Related

How can I apply a transparent background to the windowBackground

I have created a simple image using Inkscape with a transparent background, alpha(0) and at the center, I have a small logo. I then applied it to my styles like below:
<style name="SplashScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowFullscreen">true</item>
<item name="android:windowBackground">#drawable/splashscreen</item>
<item name="colorPrimary">#android:color/transparent</item>
<item name="colorPrimaryDark">#color/colorPrimary</item>
<item name="colorAccent">#color/loginHeaderBackground</item>
</style>
It works fine, however, I'm missing my main objective, its displaying a black screen with the middle icon instead of a transparent one.
What I want (User should be able to still see their phone background when the app starts to launch)
What I'm getting
Why is this?
There is an example for you. I wrote custom theme and i added this theme to my activty. You should add this your splash activity in manifest file.
<activity ...
android:theme="#android:style/Theme.TranslucentTheme"
.../>
styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TranslucentTheme" parent="android:Theme.Translucent">
<item name="android:windowBackground">#color/transparent_black</item>
</style>
<color name="transparent_black">#DA000000</color>
</resources>

Can I change to dark theme only for one single SearchView in the Activity?

My app has a Light Material Theme, but one section of my activity is dark, and I've placed a SearhView in it. The problem is then that the search icon hint is black-on-blue. Not pretty. So can I override the theme for this single View only?
The intuitive thing to do would be to change the style proerty. So I tried this, to no avail:
<SearchView
style="#android:style/Widget.Material.SearchView"
(...)
/>
(the normal style would be Widget.Material.Light.SearchView, I suppose)
Suggestions?
PS: I am not going down this rabbit hole
You can set it in your manifest. You can globally define a theme for the whole application but you can apply other themes for activities too.
For Application:
<application
android:name=".MyApp"
android:theme="#style/Theme.global">
For Activity:
<activity
android:name=".SomeActivity"
android:theme="#style/Theme.search">
UPDATE on comment:
Then set this in your styles.xml where you define your theme attributes like this:
<item name="android:searchViewStyle">#stye/MySearchViewStyle</item>
This is the default for base Searchview:
<style name="Base.Widget.AppCompat.SearchView" parent="android:Widget">
<item name="layout">#layout/abc_search_view</item>
<item name="queryBackground">#drawable/abc_textfield_search_material</item>
<item name="submitBackground">#drawable/abc_textfield_search_material</item>
<item name="closeIcon">#drawable/abc_ic_clear_mtrl_alpha</item>
<item name="searchIcon">#drawable/abc_ic_search_api_mtrl_alpha</item>
<item name="searchHintIcon">#drawable/abc_ic_search_api_mtrl_alpha</item>
<item name="goIcon">#drawable/abc_ic_go_search_api_mtrl_alpha</item>
<item name="voiceIcon">#drawable/abc_ic_voice_search_api_mtrl_alpha</item>
<item name="commitIcon">#drawable/abc_ic_commit_search_api_mtrl_alpha</item>
<item name="suggestionRowLayout">#layout/abc_search_dropdown_item_icons_2line</item>
</style>
You can define your style like this:
<style name="MySearchViewStyle" parent="Base.Widget.AppCompat.SearchView">
<item name="searchIcon">#drawable/my_incredable_search_icon</item>
</style>

Transparent Android activity trouble

I have an application where the theme can be changed between three different ones. I have two activities that are supposed to have a transparent background and look like a dialog above the previous activity.
I've searched alot for transparent activities here on stack and most of them have the same awnsers. A custom theme with a few properties to enable a transparent background for the activity in question.
The issue for me is that i need to set this custom transparent theme on the parent activity as well to achieve any transparency at all. If i only set a transparent theme on the activity i want to be transparent, it will be a solid background. I've tried everything i could think of but it all boils down to this and im not sure what im doing wrong.
This is my two different parent themes (slimmed down to the neccesary parts):
<style name="StyledActionbar" parent="Theme.Sherlock.Light.ForceOverflow">
<item name="android:textViewStyle">#style/Iksu.TextView</item>
<item name="windowContentOverlay">#null</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="Transparent" parent="Theme.Sherlock.Light.ForceOverflow">
<item name="android:textViewStyle">#style/TextView</item>
<item name="windowContentOverlay">#null</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowIsTranslucent">true</item>
</style>
StyledActionBar is the parent for my three different main themes that is used for all activities that are not supposed to have a transparent background (which is all but two).
Transparent is the parent for three themes that can be used on an activity where the background needs to be transparent.
So the parent activity has a theme based on the StyledActionBar theme. The activity i need to have transparent is based on the Transparent theme.
The background is solid in this state.
If i move:
<item name="android:windowIsTranslucent">true</item>
to StyledActionBar, almost everything works as a charm except a nasty bug in Android 4.4.2 causing the main activity to "fall behind" the OS view when using NavUtils for up-navigation to the main activity.
Any ideas?
in your manigest file
<activity
android:theme="#android:style/Theme.Translucent.NoTitleBar">
</activity>
and in your xml set
android:background="#android/transperent"
also you can use
android:alpha="0.50"
try this one more time :
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
and in the manifest file
<activity android:name=".AlertActivity"
android:theme="#style/Theme.Transparent"/>
Hope it will work for u.

How to darken a screen in android?

Say I have a menu sliding out in android and I want to darken whatever was behind it.
I tied making a full screen layout and use a countdown timer to make its background gradually go from transparent to 50% black, but it gets slow as hell.
Are there any other options to make a gradual transition? Other then making it in a snap?
Thanks!
Why don't you use a theme? Under res/values, make a styles.xml file. In that, define
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Translucent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#color/cache_color</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
</resources>
Then in your manifest:
<activity android:name="com.example.FooActivity" android:theme="#style/Theme.Translucent"></activity>

Can I create translucent + dialog theme in android?

I want my activity to look like a dialog.
Well, I achieved that using android:theme="#android:style/Theme.Dialog"
Now, I also want it to be translucent as it appears in android:theme="#android:style/Theme.Translucent"
Is there a a way to mix them both using a custom style??
Please any suggestions, thanks
EDIT: achieved something similar with this:
Now i want to add border like a dialogwindow...how can i do that???
<style name="TransparentDialog" parent="#android:style/Theme.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowFrame">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:alertDialogStyle">#android:style/Theme.Dialog</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
</style>
EDIT: Solved this. Check the answer
Finally achieved what i wanted with this:
Used this theme for my activity android:theme="#android:style/Theme.Translucent"
and gave this android:background="#android:drawable/dialog_frame"as background to the root element of my layout
That was so easy!
You'll need to combine the two themes together. One thing that might work is:
<style name="TranslucentDialog" parent="#android:style/Theme.Dialog">
<item name="android:background">"#33000000"</item>
</style>

Categories

Resources