Transparent Activity, with a faint tint of Grey - android

I am trying to have a transparent Activity, with a faint grey Color tint, over another activity. I am able to invoke the transparent activity, but I am not able to get the Greyish Tint. Please help me. Following is my code.
<style name="Theme.Transparent">
<item name="android:windowBackground">#drawable/transparent_background</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>
<drawable name="transparent_background">#FFFECA11</drawable>
No matter what colour value I provide for the drawable, it is not being reflected as the background. The definition in manifest
<activity
android:name=".DisplayHelpActivity"
android:label="#string/title_activity_display_help"
android:theme="#style/Theme.Transparent">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.INFO" />
</intent-filter>
</activity>
Can you please let me know wat is missing?
P.S. Please forget the color value. Its just random I used to test if it works.
I used the following as well
<item name="android:windowBackground">#color/transparent</item>
instead of the drawable, and in my color.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="transparent">#80ffeeca</color>
</resources>
it still has no effect. Please help me.

I don't think it's a good idea to put activities on top of each other. If you want to show something on top of your normal activity, then using a FrameLayout is a posible solution:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/main_layout" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffffff"
android:id="#+id/underlying_layout" >
<!--Put the parts of your normal activity here -->
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#88666666"
android:id="#+id/top_layout">
<!--Put the parts of the layout here,
what should be on top of your activity-->
</LinearLayout>
</FrameLayout>
Now if you want to make the top level stuff appear or disappear, then you can use the Views setVisibility() function like this:
View topLevelLayout = findViewById(R.id.top_layout);
//make it disappear with all its sub-Views
topLevelLayout.setVisibility(View.INVISIBLE);
//make it appear with all its sub-Views
topLevelLayout.setVisibility(View.VISIBLE);
UPDATE

I believe the problem lies within the value of the color itself.
#FFFECA11
The reason being that the color is broken down into four values, #AARRGGBB. The first two are the transparent values, and by using FF in your first two values, you are ensuring that it is not transparent. Try using the following value to get around 50% transparency:
#7FFECA11
For more information, see the following link: http://developer.android.com/guide/topics/resources/more-resources.html#Color

Related

Change the default color of main activity when it starts, The starting and opening default color

When user opens any application by clicking on app icon, the app starts with mainactivity.java. and its xml layout is shown to user.
I am making a splash screen with simple background color and text. But what my problem is, when it starts it shows a default layout color for a very little fraction of time and then it draws my given color. I do not want default color to be there even for that small fraction of time.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.rushi.demon.MainActivity"
android:background="#color/SplashScreen" >
<RelativeLayout
android:id="#+id/SplashScreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/SplashScreen">
<TextView
android:id="#+id/SplashText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:text="#string/splash_name"
android:textColor="#color/SplashText"
android:textSize="40sp"
android:textStyle="bold"/>
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
The SplashScreen color is shown after a lag and starting default color is shown for little time, which i do not want. I want to open this activity with my set color only from starting.
Add this to your AppTheme (theme of MainActivity) ..
<item name="android:windowDisablePreview">true</item>
Edit
Go to app -> res -> values -> styles.xml open styles.xml there you do this to the theme you have..
<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:windowDisablePreview">true</item> //add this line
</style>
The best way to achieve this is well described here, By this way Splash Activity will start instantly
Refer this: https://medium.com/#ssaurel/create-a-splash-screen-on-android-the-right-way-93d6fb444857

Android find default background color

I have an app with a simple recyclerview.
The layout is declared as follow
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/contentView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/some_id" />
</RelativeLayout>
I notice that on different devices, the recyclerView actually had a different background. In newer devices, the background is just white. On older devices, the background is light gray.
In android studio, the background color is blank in the design view.
So my question is, where does this gray color come from? How can I change it universally to white?
I can obviously just add background:white to this particular view. But is there a way to overwrite the system default?
Android default background color
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:colorBackground">
</RelativeLayout
use
android:background="?android:colorBackground"
What you are seeing is actually the background of the activity, not the recyclerview, which is transparent by default. The color did change a view time per Android version.
You can override this in your app theme.
First define the color in values/colors.xml
<resources>
<color name="background">#FF0000 </color>
</resources>
Create a themes.xml file in res/values that references that color:
<resources>
<style name="MyTheme" parent="#android:style/Theme.Light">
<item name="android:windowBackground">#color/background</item>
</style>
</resources>
and then in your AndroidManifest.xml specify this as
the theme for your activities to use.
<activity
android:name=".MyActivity"
android:theme="#style/MyTheme" />
see https://stackoverflow.com/a/10157077/4623782
it's because of theme. specify your theme in res/values/style.xml. or set manually in view definition.
<android.support.v7.widget.RecyclerView
android:id="#+id/contentView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/some_id"
android:background="#android:color/white"
/>
it will give you white background on all device
The color of the background which is set by default in any android studio project is #fafafa

How to remove the white border around the image in splash screen in full screen

I am currently working on a splash screen with an image view. The problem is that when the splash screen is shown, there is a white border around the image. So that the splash screen shows the image with the white border around. I would like to remove the white border completely. Is there any one who know the reason for this or any suggestion?
Here is my xml code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<View android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView android:id="#+id/ImageViewSplash"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:contentDescription="#string/splashImageContentDescription" />
</RelativeLayout>
I apply a transparent background in the theme/style I use for my splash pages, this way I don't have to distort the image being displayed to fit the screen size of the device. This works particularly well when using PNG files that contain a transparent background.
Here's the style I use for this "Transparent" theme:
<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>
You then apply this theme to the splash activity in your application manifest as follows:
<activity
android:name="com.masseria.homework9.SplashActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/Theme.Transparent" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
It seems to me like you could remove everything from your layout except for the ImageView. So it would look like this:
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ImageViewSplash"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:contentDescription="#string/splashImageContentDescription" />
Then you could play around with the scaleType on the image until you found one that filled the screen. If none of that works, I would suggest increasing the resolution of your image file.

ListView redraws background color whenever I scroll

I have defined a custom theme, where I am drawing a dark gradient on my window background. My ListView background is set to be transparent, however whenever I scroll, the background color turns black, and then after scrolling has stopped, goes back to the gradient color. Why is this?
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base application theme is the default theme. -->
<style name="Theme" parent="android:Theme">
</style>
<!-- Variation on our application theme that has a translucent
background. -->
<style name="Theme.DarkGradient">
<item name="android:windowBackground">#drawable/dark_gradient</item>
</style>
</resources>
Your question is answered here: http://developer.android.com/resources/articles/listview-backgrounds.html
You just need to set the cacheColorHint in order to fix your problem. :-)
Just set cacheColorHint="#00000000" in your xml listView its a transparent color
<ListView android:id="#id/android:list" android:layout_width="320dp"
android:layout_height="fill_parent" android:layout_centerHorizontal="true"
android:divider="#color/whitetxtcolor"
android:layout_weight="2" android:drawSelectorOnTop="false"
android:layout_below="#id/new_layout"
android:cacheColorHint="#000000"
></ListView>
or U can do like this also
this.getListView.setCacheColorHint(0);

Custom title bar without padding (Android)

So I am using the techniques in this thread to use a custom background for my titlebar. Unfortunately the framework places my layout inside a FrameLayout (title_container) which has padding as seen below.
(source: ggpht.com)
Is there anyway to remove the grey borders? The frame layout is defined in com.android.internal.R.id.title_container, so accessing the frame by ID would be fragile.
I was struggling with this same issue and now I have the answer!
As you probably have seen several places, you need to create a themes.xml resource:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="android:Theme">
<item name="android:windowTitleSize">44dip</item>
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground</item>
</style>
</resources>
Note it is not often mentioned in the sites talking about custom title bars you need to select this theme at the view, activity, or application level. I do it at the application level by adding android:theme property to the application:
<application android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/MyTheme">
You also need a styles.xml to define that WindowTitleBackgroundStyle. Unlike the various versions of this file I have seen floating aroung the web, I have added one additional line to the file that sets the padding to 0 which gets rid of the padding you are complaining about:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="WindowTitleBackground">
<item name="android:background">#android:color/transparent</item>
<item name="android:padding">0px</item>
</style>
</resources>
There is actually no need to use a custom layout to customise the background image. The following code in theme.xml will work:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TitlebarBackgroundStyle">
<item name="android:background">#drawable/header_bg</item>
</style>
<style name="Theme.OTPMain" parent="android:Theme">
<item name="android:windowTitleBackgroundStyle">#style/TitlebarBackgroundStyle</item>
</style>
</resources>
However, if you do actually want to use a custom title bar, then the following code will remove the margin:
ViewGroup v = (ViewGroup) findViewById(android.R.id.title);
v.setPadding(0, 0, 0, 0)
title_bar_background was set as the ID of the background image in the XML. I set android:scaleType="fitXY".
There is a lenghty thread over on anddev.org that may be able to help you out
http://www.anddev.org/my_own_titlebar_backbutton_like_on_the_iphone-t4591.html
I have followed it and successfully created my own title bar which allows me to set the padding.
Xml for my title bar:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="#+id/header"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="38px" android:layout_width="fill_parent"
android:background="#drawable/gradient">
<TextView android:id="#+id/title" android:layout_width="wrap_content"
android:gravity="center_vertical" style="#style/PhoneText"
android:layout_alignParentLeft="true"
android:text="New Title" android:background="#android:color/transparent"
android:layout_height="wrap_content" android:layout_alignParentTop="true"
android:padding="5dip" android:layout_marginBottom="7px"/>
<TextView android:id="#+id/time" android:layout_width="wrap_content"
android:gravity="center_vertical" style="#style/PhoneText2"
android:layout_alignParentRight="true"
android:text="Test Text" android:background="#android:color/transparent"
android:layout_height="wrap_content" android:layout_alignParentTop="true"
android:padding="4dip" android:layout_marginBottom="7px"/>
</RelativeLayout>
The above creates a small gray bar with text aligned to the right and left sides
I got rid of the padding by getting the title container and setting the padding to 0. It works on Android 4.
titleContainerId = (Integer)Class.forName("com.android.internal.R$id").getField("title_container").get(null);
ViewGroup vg = ((ViewGroup) getWindow().findViewById(titleContainerId));
vg.setPadding(0, 0, 0, 0);
As mentioned by dalewking, you can change the Manifest like this:
<application android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/MyTheme">
But it did not work for me until I added
android:theme="#style/MyTheme"
to the activity it self like:
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="#style/CustomTheme" >
</activity>
As of 4.2 and ADT 21 when creating a default layout standard dimensions are added to the parent container:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
</RelativeLayout>
Values are located in res/dimens.xml:
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
Either remove them from the parent or change the dimens.xml values to your desired values.
I added the following padding item the AppTheme in styles.xml
<style name="AppTheme" parent="AppBaseTheme">
...
<item name="android:padding">0dp</item>
...
</style>
The Application manifest uses that theme:
<application
...
android:theme="#style/AppTheme" >
...
This resolved it for me.

Categories

Resources