In android, if you create an imageview in the xml code like this:
<ImageView
android:id="#+id/picture_avatar"
android:layout_width="90dp"
android:layout_height="110dp"
android:background="#bdbdbd" />
How can you tell in the java code, if it has a set image?
There is another button that sets an image using the setImageBitmap function. So I want to tell if it has an image or not.
Thanks
pictureavatar.getDrawable() == null
If true, then no image else it has an image
Related
I have an issue with the GIF Resizing.
My GIF dimensions is 136*136 px and I'm trying to load it into an image view (that has its width and height set as wrap_content) using Glide library. But the GIF ends up taking the entire screen.
My XML file code snippet looks like below:
ImageView
android:id="#+id/loading_animation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
tools:src="#drawable/gif_loading_animation"
android:foregroundGravity="center" />
And My main activity code looks something like this:
Glide.with(getContext())
.load(R.drawable.gif_loading_animation)
.asGif()
.into(loadingAnimation);
Is there any solution to avoid resizing without using any hard code parameters width and height.
:)
You can try using .override(Target.SIZE_ORIGINAL)
Glide.with(getContext())
.load(R.drawable.gif_loading_animation)
.asGif()
.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
.into(loadingAnimation);
Is it possible to make chamfered corner in Android Button like this (pointy corner)??
All reference i've searched is to create rounded corner, not chamfered.
Please help. Thank you for any answer.
You can use Button and set this image as background android:background="#drawable/chamfered_edge_img" (i hav used above image as chamfered_edge_img, u can use same image without text and add text to button with android:text="My Button Name")
Code:
<Button
android:layout_width="150dp"
android:layout_height="50dp"
android:scaleType="fitXY"
android:background="#drawable/lcoyg"
style="?selectableItemBackground"
/>
Result:
I have a ImageView with the following layout
<ImageView
android:id="#+id/view_row_circular_icon_with_text_icon"
style="#style/ImageView"
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_gravity="right|center_vertical"
android:padding="5dp"
android:src="#drawable/ic_broadband_router_white"/>
The android:src property is useful for previewing this component.
And I set the image I want do display with the following
ImageView mIcon = (ImageView) findViewById(R.id.view_row_circular_icon_with_text_icon_bg);
mIcon.setImageDrawable(rowEntry.getIcon());
rowEntry.getIcon() returns a Drawable.
The end result is both the image from android:src property and the image set from mIcon.setImageDrawable() in the ImageView.
How can I programmatically override the image so that only the latter is shown?
As i can see that your setting image of a another view which
R.id.view_row_circular_icon_with_text_icon_bg
Check the proper id and set the image
I am making an android app where the same imageview is displayed every time the user enters a value. but I want the imageview to be changed every time the user enters a value. I wrote a code to do this but the problem is after the first image is displayed I face black screen and it takes me to the first page in the app, it doesn't crash just shows black screen.
here is the imageview code in xml file:
<ImageView
android:id="#+id/ImageSuccess"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginBottom="20dip"
android:layout_marginTop="20dip"
android:scaleType="centerInside"
android:src="#drawable/image1" />
and here where I changed the imageview in java file:
ImageView myImage= (ImageView) findViewById(R.id.ImageSuccess);
if(userVlue.equals("SCHOOL")){
myImage.setImageResource(R.drawable.image1);
}
else if(userVlue.equals("CAR")){
myImage.setImageResource(R.drawable.image2);
}
else if(userVlue.equals("TOY")){
myImage.setImageResource(R.drawable.image3);
}
One of myImage or userVlue is not set properly and probably is null.
Debug and share logs. Your partcular activity is getting distroyed probably because of nullpointexception hence returning to main activity in backtrack.
I tried with a sample app and your logic is working perfectly.
You are handling user action on some UI element, when you do findViewById, cotext is that UI element, so this method searches ImageSuccess in children of it. Try giving page layout as rootlayout and do rootlayout.findViewById("ImageSuccess");
I found the solution finally, the black screen appeared because the images were only in the drawable file, so I needed to add the images in all drawbridge folders such as drawable-ldp, drawable-ldpi etc...., so that the app can work in different phone sizes.
I've tried to put the intern icons of Android (anrdoid.R.drawable.bla) into an ImageButton
and I wanted to change the color of Icon (not the Background!), but it doesn't work like I want to.
Here is what I've tried:
my ImageButton from the Layout:
<ImageButton
android:id="#+id/imageButton1"
android:layout_marginTop="100dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/background"
android:src="#android:drawable/ic_lock_silent_mode" />
what I've tried in my Activity:
Drawable myIcon = getResources().getDrawable( android.R.drawable.ic_lock_silent_mode);
ColorFilter filter = new LightingColorFilter( R.color.blue, R.color.blue);
myIcon.setColorFilter(filter);
No matter what Values I've tried for the LightingColorFilter it always gives the same result. The icon inside the Imagebutton gets dark. But thats not what I wnated. I just wanted to apply a color from my colors.xml, it somehow doesnt work out.
Is this even the right direction I'm going? Or is there another opertunity (And I don't mean coloring myself in Photoshop and putting them into the drawables folder)
this worked for me, for example it will paint in dark gray:
ImageButton imgBtn = (ImageButton) findViewById(R.id.imageButton11); // image button
imgBtn.setColorFilter(getResources().getColor(android.R.color.darker_gray), Mode.SRC_ATOP);