How to add Image without this white background? - android

enter image description here
Here it is a XML file,
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="10dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardBackgroundColor="#fff2f2"
android:foreground="?android:attr/selectableItemBackground"
app:cardCornerRadius="12dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/tick"
android:id="#+id/image2"/>
</LinearLayout>
And Mainactivity.java,
item2List.add(new Items2(R.drawable.checked));

The default color of CardView is White. If you want to change it to some other color use following code.
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="#color/white">
</android.support.v7.widget.CardView>
or you can set cardBackgroundColor to transparent(if you don't want any color) by setting cardBackgroundColor as
app:cardBackgroundColor="#android:color/transparent"

Set app:cardBackgroundColor="#android:color/transparent" instead of app:cardBackgroundColor="#fff2f2".
This will take background of your Image rather than force white background.

Here, I have no idea about your image is .png or .jpeg, but if your image is not .png then take .png image and if you have already taken .png image than set cardview background transparent.
Here, use the cardBackgroundColor attribute to remove color and set transparent and cardElevation attribute to remove the drop shadow.
Please try below:-
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardElevation="0dp"
app:cardBackgroundColor="#android:color/transparent" >
If you you use API level 21 and higher and in case of cardBackgroundColor not work properly you can use android:backgroundTint. In my case it works.
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardElevation="0dp"
android:backgroundTint="#android:color/transparent">

Related

CardView for Android 9.0 has space black blank, how to remove the black space

CardView for Android has black spaces, how to remove it. i need help.
this is java or android problem.
enter image description here
<android.support.v7.widget.CardView
android:id="#+id/cv_result_knowledge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/ll_result_header"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
android:visibility="gone"
app:cardBackgroundColor="#color/black_transparent40"
app:cardCornerRadius="#dimen/d12"
app:cardElevation="#dimen/d1"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/d10"
android:layout_marginTop="#dimen/d2">
</RelativeLayout>
</android.support.v7.widget.CardView>
Its because you set the background color to black, your Relative Layout has margin set so the black card background is visible in the margin area. Just remove the card background or remove margins, whichever suits you.
<android.support.v7.widget.CardView
android:id="#+id/cv_result_knowledge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/ll_result_header"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
android:visibility="gone"
app:cardBackgroundColor="#color/black_transparent40" -<REMOVE THIS
app:cardCornerRadius="#dimen/d12"
app:cardElevation="#dimen/d1"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/d10" -<REMOVE THIS
android:layout_marginTop="#dimen/d2"> -<REMOVE THIS

Make ImageView have dark transparency

I want to add the transparent black color on top of the image and make it darker.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/rest_image"
android:layout_width="match_parent"
android:layout_height="150dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
/>
</RelativeLayout>
I can set the alpha parameter but the color change is in white.
I want to make the darker image like this.
How can i do it in xml or Java code. I will set it based on condition.?
Thanks.
What you need is called tinting. Apply a tint to your ImageView:
<ImageView
...
app:tint="#6F000000"
/>
Easiest/Fastest solution would be in XML
Add a second layer (can be a View, doesn't have to be an ImageView) on top of your ImageView, with the desired color/alpha. Show/Hide it when needed.
<ImageView
android:id="#+id/rest_image"
android:layout_width="match_parent"
android:layout_height="150dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
/>
<View
android:id="#+id/overlay_image"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background=“#color/yourColorWithAlpha"
/>
</RelativeLayout>
You can add foreground tint with tint mode.
Make sure you add alpha channel in your foreground color.
foreground="##AARRGGBB"
AA = alpha channel in HEX
R,G,B = Red, Blue, Green.
<ImageView
android:id="#+id/vidthumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:foreground="#96222f3e"
android:foregroundTintMode="src_atop"/>
Try this second imageview will set the transparent color. Adjust the height according to your need.
500000 - last 4 digits stands for black color and first two stands for alpha you want to set.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/rest_image"
android:layout_width="match_parent"
android:layout_height="150dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
/>
<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#500000"
/>
</RelativeLayout>

Android remove white border from cardview on API level 4

my android version is 4.2 and i'm trying to remove white border and space from that but my solution as card_view:cardPreventCornerOverlap="false" from xmlns:app="http://schemas.android.com/apk/res-auto" namespace doesnt work correctly
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:elevation="0dp"
card_view:cardPreventCornerOverlap="false">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/market_item_background">
<ImageView
android:id="#+id/market_thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:scaleType="centerCrop"/>
</RelativeLayout>
this is part of my application which i used CardView
Try setting
setCardElevation(0);
setMaxCardElevation(0);
and
card_view:cardPreventCornerOverlap="false"
Source: Cardview - white border around card
After much research only thing work for me with pre lollipop devices
with using both
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true"
in CardView,
this is a old question but might help somebody
Replace android:layout_margin="10dp"
for android:layout_padding="10dp"
I think that setting setMaxCardElevation(0) will be enough in that case.
No need in setCardElevation(0) or card_view:cardPreventCornerOverlap="false"
I set card background color to transparent and it makes the white border disappear
app:cardBackgroundColor="#android:color/transparent"

Android: why are CardView margins not showing white background?

I have set up a CardView in a RecyclerView list. The layout_marginTop and layout_marginBottom are showing a grey color rather than the white background I had hoped to see (image below). Any ideas on how to get the top and bottom margins to show a white background?
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardCornerRadius="6dp"
android:layout_margin="4dp">
<TextView
android:id="#+id/cardText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:background="#android:color/white" />
</android.support.v7.widget.CardView>
Removed the TextView background and added this background to the CardView:
"card_view:cardBackgroundColor="some color""
Add some margin to card
<android.support.v7.widget.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="7dp"
app:cardCornerRadius="2dp"
app:cardElevation="4dp">
</android.support.v7.widget.CardView>
Make sure you're actually populating it with data from your domain model, i.e. check that you've implemented <data> and <variable> tags and that you've set your android:text="#{}" to the appropriate object.

Transparent background on CardView - Android

I want to do transparent background on CardView.
I know backgroundColor but i have image on my Layout.
Do you know how do it? Or something which work as cardview but i will set a transparent background?
Regards
Setup your CardView to use the cardBackgroundColor attribute to remove color and cardElevation attribute to remove the drop shadow. For example:
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/myCardView"
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardBackgroundColor="#android:color/transparent"
card_view:cardElevation="0dp">
For a full list of supported attributes see here: https://developer.android.com/reference/android/support/v7/widget/CardView.html
If you are using an older API, you will need to call these two functions on your CardView instead:
myCardView.setCardBackgroundColor(Color.TRANSPARENT);
myCardView.setCardElevation(0);
in SDK version 21 or higher steps to make Android CardView transparent.
Set android:backgroundTint="#android:color/transparent". This is CardView attribute to set background.
Set android:cardElevation="0dp" to remove the shadow.
For example, here is small xml code to create transparent CardView
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardBackgroundColor="#android:color/transparent"
app:cardElevation="0dp" />
In my case, I used the attribute android:backgroundTint="#color/some_color",it is only used en API level 21 and higher. And color #50000000 for example.
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
card_view:cardCornerRadius="3dp"
app:cardElevation="0dp"
android:backgroundTint="#color/negro_label"
>
use app:cardBackgroundColor="#android:color/transparent"
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
app:cardCornerRadius="16dp"
app:cardElevation="16dp"
app:cardBackgroundColor="#android:color/transparent" >
<--inside cardlayout-->
</android.support.v7.widget.CardView>
This should work on API 17
cardView.setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent));
Just add background color app:cardBackgroundColor="#0000"
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardBackgroundColor="#0000">
You must have cardView to make image circle shape
<androidx.cardview.widget.CardView
android:layout_width="50dp"
android:layout_height="50dp"
app:cardCornerRadius="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:elevation="0dp"
app:cardBackgroundColor="#00424242"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/play_icon"
android:padding="5dp"
android:background="#19000000"
android:contentDescription="TODO" />
</androidx.cardview.widget.CardView>

Categories

Resources