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>
Related
Currently all my text and hint colour by default is all white, although I do ok when I'm able to change them in xml file, but certain stuff like TextInputLayout text counter doesn't allow colour change
below are my colors.xml
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#5CCDCC</color>
below are my styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/GreenishBlue</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowLightStatusBar">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
AndroidManifest was modified like this:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/CustomTheme">
And the file res/values/styles.xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:textColor">#000</item> //black color for text
<item name="android:textColorHint">#939393</item> //Gray color for hint
</style>
</resources>
Adding below code to your existing AppTheme will change default text color in controls where text color is not set inline in xml, using different style or dynamically.
<item name="android:textColor">#000000</item>
<item name="android:textColorHint">#666666</item>
I've used inbuilt theme Theme.AppCompat.NoActionBar for my app. But it gives complete black background. I want to change this black background to gray one. So I tried to customize my theme as following:
Here is my styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="MyTheme"> // Using Customized theme.
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
//Customize the Theme.
<style name="MyTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:backgroundDimAmount">0.8</item>
</style>
Here I want to lighten my background color so I'm using android:backgroundDimAmount but it is not working.
I've also used following:
<style name="MyTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:background">#707070</item>
</style>
This changes the background color, but gives me weird results as following screen shot:
Where as My actual activity looks like following screen shot:
So my question how can I lighten or possibly change the background color?
you want this
<item name="android:background">#color/<mycolor></item>
<item name="android:windowBackground">#color/<mycolor></item>
<item name="android:colorBackground">#color/<mycolor></item>
remember to change it in all styles xmls
you should use style as this in style.xml.....
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.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:background">#color/gray</item>
<item name="android:windowBackground">#color/gray</item>
<item name="android:colorBackground">#color/gray</item>
</style>
</resources>
and in colors.xml make this.....
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="gray">#707070</color><!--this your color-->
</resources>
the final out put
Replace android:background to android:windowBackground.
Also change the hardcoded color (e.g #707070) to color reference (e.g #color/myYellowBackgroundColor) .
When using android:windowBackground you tell android to affect background of child's view only inside the main activity on the screen.
use this in your styles.xml file
<item name="android:statusBarColor">#color/yourcolor</item>
remember to add your color in color.xml file. don't hardcode your color.
I'm trying to set up my styles to make all buttons a particular color combination, specifically blue with white text. Here's my main styles.xml:
<resources>
<style name="CustomTheme" parent="MaterialDrawerTheme.Light.DarkToolbar">
<!-- various items -->
<item name="android:buttonStyle">#style/ButtonStyle</item>
</style>
<!-- a couple of other styles -->
<style name="ButtonStyle" parent="android:style/Widget.Button">
<item name="android:textSize">19sp</item>
<item name="android:textColor">#color/primaryTextContrast</item>
<item name="android:background">#color/primary</item>
</style>
</resources>
And in the manifest:
<application
android:name=".CustomApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/application_name"
android:theme="#style/CustomTheme">
color/primary is dark blue, and color/primaryTextContrast is white. On Lollipop, the button looks perfect. On a 4.1 device, it's light gray with black text. Every resource I've found for doing this looks exactly like what I'm doing so I don't know what I'm missing here.
I'm having a similar issue with controlling text size in the base style definition as well.
Update: here are the colors.
<resources>
<color name="primary">#3F51B5</color>
<color name="dark">#303F9F</color>
<color name="accent">#FFCA28</color>
<color name="background">#android:color/white</color>
<!-- Color for text displayed on top of the primary or dark color -->
<color name="primaryTextContrast">#android:color/white</color>
<!-- Color for text displayed on the background color (which I think will always be white) -->
<color name="basicText">#color/primary</color>
<!-- Color for text displayed on the accent color -->
<color name="accentText">#303F9F</color>
</resources>
Here's v19/styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="FullscreenTheme" parent="MaterialDrawerTheme.Light.DarkToolbar.TranslucentStatus">
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>
Here's v21:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="CustomTheme">
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowSharedElementEnterTransition">#android:transition/move</item>
<item name="android:windowSharedElementExitTransition">#android:transition/move</item>
</style>
</resources>
I don't think either of these is what's making it work properly on 5.1.
Using AppCompat 22.1.+ (22.2.0 should work too), I defined a Style like this:
<style name="MyApp.Button.Red" parent="Base.Widget.AppCompat.Button">
<item name="colorButtonNormal">#color/primary</item>
<item name="android:colorButtonNormal">#color/primary</item>
<item name="android:textColor">#android:color/white</item>
</style>
and then applied the theme in a button using the native theme attribute from android namespace, as said in this awesome post from Chris Banes.
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sign_up_button"
android:theme="#style/MyApp.Button.Red" />
I tried adding buttonStyle without the android: prefix and it solved the problem. Yeah, weird.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="buttonStyle">#style/ButtonStyle</item>
<item name="android:buttonStyle">#style/ButtonStyle</item>
</style>
gradle:compile 'com.android.support:appcompat-v7:22.2.0'
For theme to work properly in android lollipop, you need to extend
ActionBarActivityinstead of Activity.
By doing this change,your theme setting should work properly.
This is general for other people that for lower version of android,you should not use android: tag in item-name definition
`
I have a transparent theme Activity but this theme will make the Activity 100% transparent.
I need a code such that the Activity will be 50% Transparent. This is my code:
<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>
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">#80000000</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>
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">