This question already has answers here:
Android getResources().getDrawable() deprecated API 22
(16 answers)
Closed 4 years ago.
This is the line in question. I have it the same way the textbook lists it, but am having issues converting the line to ContextCombat since getDrawable() has been deprecated.
buttonItem.setImageDrawable(getResources().getDrawable(painting.getId()));
You can try using ContextCompat.getDrawable(getActivity(), R.drawable.name);. This will return a styled Drawable as instructed by your Activity's theme. Your code would be more or less as shown below:
buttonItem.setImageDrawable(ContextCompat.getDrawable(getActivity(), painting.getId()));
NOTE: I'm assuming that painting.getId() returns the resource id for the image you want to set as your button's drawable. Also, if you are doing this inside an Activity, you should use the keyword this instead of getActvity().
Related
This question already has answers here:
Unfortunately MyApp has stopped. How can I solve this?
(23 answers)
Closed 2 years ago.
I use two edit fields and get their texts in on lick method of a button, but when i click button my app crashed. please help me to resolve this problem.
I am fresh one here, if I make any mistake in uploading my question ignore it
thanks..!
Text Field returns a string, which can be a non-number string.
A try-catch block would help if the method could not parse it into an integer.
This question already has answers here:
How to disable Button when TextField is empty?
(3 answers)
Closed 3 years ago.
I want to disable the button when the text fields are empty.
I have created two fields with the onKeyReleased property
Sorry i sent it unintentionally.
Something like btn.disableProperty().bind(field.textProperty().isEmpty()) should work.
In the future please add a compilable skeleton and what you have tried so far to your question. That makes it way easier to help.
And welcome to stack overflow!
This question already has answers here:
Passing an Object from an Activity to a Fragment
(8 answers)
Closed 7 years ago.
I just want to use getActivity().data in my fragment to pull in the data object.
It's not working though. Eclipse says that data cannot be resolved.
It looks like there is plenty of information about how to use Bundle to do this.
However, I am wondering how to use getActivity in particular.
Although using Bundle is the preferred way and following way must be avoided but just to answer your question, try making the data variable static and access it by typecasting the activity ((YourActivity)getActivity()).data.
This question already has answers here:
Oval Gradient in Android
(5 answers)
Closed 9 years ago.
I want to perform a gradient effect that shines from bottom of the layout as appear in the following picture. Notice that it is not a regular tag with start colour and end colour because I tried those but I haven't reach to the required solution. Also I don't want to set the background with a picture because I’m concern of quality issues. Please help. Thank you.
You can't do this using XML drawables in Android. I recommend using images.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
marquee text in android
in my app i want to have a news banner with the words moving to one side like tv .. i don't really know how to run that kind of animation .. and should the banner be a TextView ? i'm not really sure of anything .. so i just need the xml format of such thing, Thankss!
This is commonly referred to as a ticker or marquee. Here's a tutorial on how to make one.
Edit: Here's another tutorial.
Edit: Here's another stackoverflow question about the same thing.
Edit: And another.