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
Related
I have a LottieAnimationView in my xml file. I want to add custom image that comes dynamically from backend(avatar image) in that lottie animation view, I mean in lottie animation view add image in its background. This is my LottieAnimationView:
<com.airbnb.lottie.LottieAnimationView
android:id="#+id/lottie_animation"
android:layout_width="110dp"
android:layout_height="110dp"
app:lottie_autoPlay="true"
app:srcCompat="#drawable/custom"
app:lottie_rawRes="#raw/photo_animation"
app:lottie_loop="true"
app:lottie_speed="2.5" />
But its only showing my animation, not showing imageview at all.
Could you post any ideas how can I handle it?
I making a drawing pad for teachers, i want to include geometrical shapes in it, there is a button on click of which a shape is displayed.
What i am doing now is i created an image view already and set its visibility to gone, on button i am making it visible.
<ImageView
android:id="#+id/ivReact"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#drawable/rectangle"
android:visibility="gone"
android:layout_centerInParent="true"
/>
i want the previous image to be there, when a button is clicked the same image should be added twice in the layout and if the button clicked again it should be added again and go on.
is it possible to do that?
Use this code inside onclick
ImageView imageview = new ImageView(MainActivity.this);
RelativeLayout relativelayout = (RelativeLayout)findViewById(R.id.relativeLayout);
LinearLayout.LayoutParams params = new LinearLayout
.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
// Add image path from drawable folder.
imageview.setImageResource(R.drawable.demo_new_image);
imageview.setLayoutParams(params);
relativelayout.addView(imageview);
create a recycler view and put a image view there. Create a arraylist. Onclick add same image to the arraylist and apply adapter.notifyDataSetChanged().
You have to update image programmatically when button is clicked:
imageView.setImageResource(R.drawable.your_image);
EDIT:
If you have ImageViews in LinearLayout, you can simply create new and add to layout:
ImageView imageView = (ImageView) LayoutInflater.from(context).inflate(R.layout.image_view_layout_name, null);
linearLayout.addView(imageView);
I asked a question before on how I can change the color of the default android drawable star into yellow, rather than white, and I got an answer to do this:
Drawable drawable = getResources().getDrawable(android.R.drawable.btn_star);
drawable.setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP);
Here is my star:
android:onClick = "star"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:background="#android:drawable/btn_star"
/>
But, the star is still white (Image below) Why wasn't the setColorFilter working? The star's edges turn yellow when I click on it... How can I keep the star yellow using the android's provided star drawable?
Change your onclick listener to this
public void star (View object){
object.getBackground().setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP);
}
I believe android creates a specific drawable object for each widget that uses a drawable.
If you ask why do get the edge glow yellow, simply it's the default theme for this drawable, if you removed your code it will still glow yellow at edges.
If you want to change it on loading, you can write the code in onCreate() if you are using activity
View object = findViewById(R.id.object_id);
object.getBackground().setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP);
You are doing it all wrong.
You have set the background in xml.
Than you are creating a Drawable object in java and apply color filter on it.
Those two are totally different with no connection at all.
Do this :
(I am assuming that you are using a ImageButton in layout xml)
<ImageButton
android:id="#+id/imageButton"
android:onClick="star"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentTop="true" />
Now in your activity class's onCreate() method do :
ImageButton btnStar = (ImageButton) findViewById(R.id.imageButton);
Drawable drawable = getResources().getDrawable(android.R.drawable.btn_star);
drawable.setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP);
btnStar.setBackground(drawable);
This will set the modified drawable as your ImageButton's Background.
You can apply same logic for Button, ImageView, etc.
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
<RelativeLayout
android:id="#+id/widget"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/my_background"
android:orientation="vertical" >
And now I want to change this background to "#drawable/your_bck" using RemoteViews. I tried something like this
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),R.drawable.yout_bck);
remoteViews.setImageViewBitmap(R.id.widget, bitmap);
But i then it shows "Widget failed to load"
It must be as a background because i need to set a text on the center of image :)
You're calling setImageViewBitmap on a RelativeLayout. A RelativeLayout is not an ImageView. You could put an ImageView in there instead that fills the RelativeLayout and call it on that.