how to check if TextView has image in android

textview android example
android textview design example
how to set text to textview in android dynamically
textview in android javatpoint
android textview source code
edittext in android

I have a layout with multiple TextView's. When the user clicks one I check if the the TextView has a background. If it has a background I remove it, else if it doesn't I set it.

Here is an example of my code:

<?xml version="1.0" encoding="utf-8"?>


So my question is, how do I check if the TextView already has a background set?


if( textView.getBackground() == null) {
                    Log.i("here", "null");


                 if(textView.getBackground() != null) {
                     Log.i("here", "not null");



You can achieve this with the following code:


import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    protected void onCreate(@Nullable Bundle savedInstanceState) {

        TextView textView = findViewById(;
        textView.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if (hasBackground(v)) {
                } else {

    private boolean hasBackground(View v) {
        return v.getBackground() != null;

TextView, When a view has focus and the user navigates away from it, the next view is searched for starting from the rectangle filled in by this method. String  Set up Detector Processor. To detect the text straight from camera we have to implement Detector Processor which will handle text detections when ever they become available. There are two methods receiveDetections() will receive the text when ever they are ready to use. Here we have shown it in the TextView.

You can get the Background-Drawable by using


If it is null, no Background is set, otherwise it is. Then you can do something like this:

if(myTextView.getBackground() == null)

android.widget.TextView, An editable text view that shows completion suggestions automatically while the user is typing. The list of suggestions is displayed in a drop  In Android, CheckedTextView is an extension of normal TextView that supports the checkable interface and displays it. It has a checkbox along with some text. It is mainly used in a ListView where we want to show which item is selected or not. checkmark attribute is used to provide a graphic or a drawable to CheckedTextView.

This will definitely fulfil your requirement -

TextView tv = findViewById(;
int count = 1;

tv.setOnClickListener(new View.OnClickListener()
    public void onClick(View view)
        if(tv.getBackground() == null)
            count = count+2;
        else if(count%2 != 0)

AutoCompleteTextView, View assertion simple test. In this example, SimpleActivity contains a Button and a TextView . When the button is clicked, the content of  Widget refers to the elements of the UI (User Interface) that helps user interacts with the Android App. TextView is one of many such widgets which can be used to improve the UI of the app. TextView refers to the widget which displays some text on the screen based on the layout, size, colour, etc set for that particular TextView.

Espresso basics, A checkbox is a specific type of two-states button that can be either See the Checkboxes guide. From class android.widget.TextView  Now to have an example application on converting TextView to image, you create a new Android project. Then in the activity_main.xml file, you add a TextView inside a ScrollView as shown below. Then in the activity_main.xml file, you add a TextView inside a ScrollView as shown below.

CheckBox, In the above code, we have taken name as Edit text, when user click on button it will take data and check that given string contains “point”. How to place textview text above imageview image without programmatically method. TextView text can be easily replaceable above imageview image using layout xml file in relative layout. So here is the complete step by step tutorial for Android overlay textview over imageview example via xml. Note : Put image inside drawable-hdpi folder. Download sample image from below and copy into drawable-hdpi folder.

How to use equals () in Android textview?, Drawables are a good way to boost Android textviews by adding images in any of four I'm beginning with one of the most basic cases, that you may know. Our TextView has four properties that let us specify images to be set around it. If you’ve ended up in a situation where you need to give super powers to your humble TextView and this super power includes : From documentation it clearly says that tag will be replaced with a…