Android Text over image Android App Development: Overlay Text On Image or Other Layout in …
Thursday, January 31, 2019

Android Text over image Android App Development: Overlay Text On Image or Other Layout in …

Stack Overflow

  1. Log In
    Sign Up

  2. current community

    • Stack Overflow


    • Meta Stack Overflow

    your communities

    Sign up or log in to customize your list.

    more stack exchange communities

    company blog

    • Tour

      Start here for a quick overview of the site

    • Help Center

      Detailed answers to any questions you might have

    • Meta

      Discuss the workings and policies of this site

    • About Us

      Learn more about Stack Overflow the company

    • Business

      Learn more about hiring developers or posting ads with us

By using our site, you acknowledge that you have read and understand our Cookie Policy , Privacy Policy , and our Terms of Service .

Android Text over image

Ask Question

up vote
down vote



I have an imageView with an image, over that image I want to place a text. How can I achieve that?

android android-imageview android-image

share | improve this question

edited Oct 16 ’13 at 9:55



asked Mar 9 ’11 at 8:09



  • 1

    Simple way is to take a textView and set it background as you do in ImageView. it will do your work easy..
    –  Xar E Ahmer
    May 23 ’14 at 12:08

  • just look at below link. I hope it will help u……
    –  Ganesh Katikar
    Sep 26 ’14 at 17:19

add a comment  | 

9 Answers




up vote
down vote

That is how I did it and it worked exactly as you asked for inside a RelativeLayout:

<RelativeLayout xmlns:andro android: android:layout_width="fill_parent" android:layout_height="fill_parent" > <ImageView android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/myImageSouce" /> <TextView android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@id/myImageView" android:layout_alignTop="@id/myImageView" android:layout_alignRight="@id/myImageView" android:layout_alignBottom="@id/myImageView" android:layout_margin="1dp" android:gravity="center" android:text="Hello" android:textColor="#000000" />

share | improve this answer

edited Feb 9 at 9:40



answered Nov 25 ’11 at 15:23



  • Thanks a ton for this example. I tried to use the compoundedDrawable textview but there I am not able to set an image url. But it’s important to use this workaround in a relative layout for the layout_align settings to be recognized.
    –  AntonSack
    Oct 5 ’13 at 11:17

  • putting the id of control to the alignment solved a lot, thanks
    –  Black Baron
    Oct 15 ’17 at 0:25

add a comment  | 

up vote
down vote

You may want to take if from a diffrent side: It seems easier to have a TextView with a drawable on the background:

 <TextView android: android:background="@drawable/rounded_rectangle" android:layout_width="wrap_content" android:layout_height="wrap_content" </TextView>

share | improve this answer

answered Oct 26 ’12 at 14:56



  • 9

    the problem with this answer is you cant control the background attributes like imageView . scale for example .
    –  Jesus Dimrix
    Sep 8 ’13 at 12:28

add a comment  | 

up vote
down vote

You could possibly

  • make a new class inherited from the Class ImageView and
  • override the Method onDraw. Call super.onDraw() in that method first and
  • then draw some Text you want to display.

if you do it that way, you can use this as a single Layout Component which makes it easier to layout together with other components.

share | improve this answer

answered Mar 9 ’11 at 8:14



add a comment  | 

up vote
down vote

You want to use a FrameLayout or a Merge layout to achieve this. Android dev guide has a great example of this here: Android Layout Tricks #3: Optimize by merging .

share | improve this answer

edited Oct 16 ’13 at 9:45



answered Mar 9 ’11 at 8:14

Hakan Ozbay


add a comment  | 

up vote
down vote

There are many ways. You use RelativeLayout or AbsoluteLayout.

With relative, you can have the image align with parent on the left side for example and also have the text align to the parent left too… then you can use margins and padding and gravity on the text view to get it lined where you want over the image.

share | improve this answer

edited Apr 15 ’15 at 10:57

Philipp E.


answered Mar 9 ’11 at 8:14



  • 1

    I came upon this method by accident. But it is very handy when you want to put some text over an imagebutton or an imageview. Example – put the current temperature over the image of the current conditions.
    –  Phobos
    Mar 9 ’11 at 8:26

add a comment  | 

up vote
down vote

You can use a TextView and change its background to the image you want to use

share | improve this answer

edited Feb 6 ’12 at 17:26



answered Oct 31 ’11 at 18:46

  • the problem with this answer is you cant control the background attributes like imageView . scale for example .
    –  Jesus Dimrix
    Sep 8 ’13 at 12:25

add a comment  | 

up vote
down vote

For this you can use only one TextView with android:drawableLeft/Right/Top/Bottom to position a Image to the TextView. Furthermore you can use some padding between the TextView and the drawable with android:drawablePadding=""

Use it like this:

<TextView android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableBottom="@drawable/yourDrawable" android:drawablePadding="10dp" android:text="Look at the drawable below"/>

With this you don’t need an extra ImageView. It’s also possible to use two drawables on more than one side of the TextView.

The only problem you will face by using this, is that the drawable can’t be scaled the way of an ImageView.

share | improve this answer

answered Sep 5 ’13 at 11:35

Steve Benett


add a comment  | 

up vote
down vote

Try the below code this will help you`

 <RelativeLayout android:layout_width="match_parent" android:layout_height="150dp"> <ImageView android:layout_width="wrap_content" android:layout_height="match_parent" android:src="@drawable/gallery1"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:background="#7ad7d7d7" android:gravity="center" android:text="Juneja Art Gallery" android:textColor="#000000" android:textSize="15sp"/>

share | improve this answer

answered Jan 2 ’16 at 8:57

Akhi Prajapati


add a comment  | 

up vote
down vote

The below code this will help you

public class TextProperty
private int heigt; //读入文本的行数
private String []context = new String[1024]; //存储读入的文本
public TextProperty(int wordNum ,InputStreamReader in) throws Exception int i=0; BufferedReader br = new BufferedReader(in); String s; while((s=br.readLine())!=null) if(s.length()>wordNum) int k=0; while(k+wordNum<=s.length()) context[i++] = s.substring(k, k+wordNum); k=k+wordNum; context[i++] = s.substring(k,s.length()); else context[i++]=s; this.heigt = i; in.close(); br.close();
public int getHeigt() return heigt;
public String[] getContext() return context;

public class MainActivity extends AppCompatActivity
private Button btn;
private ImageView iv;
private final int WORDNUM = 35; //转化成图片时 每行显示的字数
private final int WIDTH = 450; //设置图片的宽度
public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); iv = (ImageView) findViewById(; btn = (Button) findViewById(; btn.setOnClickListener(new View.OnClickListener() public void onClick(View v) int x=5,y=10; try TextProperty tp = new TextProperty(WORDNUM, new InputStreamReader(getResources().getAssets().open("1.txt"))); Bitmap bitmap = Bitmap.createBitmap(WIDTH, 20*tp.getHeigt(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setColor(Color.WHITE); paint.setTextAlign(Paint.Align.LEFT); paint.setTextSize(20f); String [] ss = tp.getContext(); for(int i=0;i<tp.getHeigt();i++) canvas.drawText(ss[i], x, y, paint); y=y+20;; canvas.restore(); String path = Environment.getExternalStorageDirectory() + "/image.png"; System.out.println(path); FileOutputStream os = new FileOutputStream(new File(path)); bitmap.compress(Bitmap.CompressFormat.PNG, 100, os); //Display the image on ImageView. iv.setImageBitmap(bitmap); iv.setBackgroundColor(Color.BLUE); os.flush(); os.close(); catch (Exception e) // TODO Auto-generated catch block e.printStackTrace(); );

share | improve this answer

answered Jul 14 ’16 at 3:32



add a comment  | 

Not the answer you’re looking for? Browse other questions tagged android android-imageview android-image or ask your own question .


7 years, 9 months ago


110,573 times


10 months ago



how to write a text view on the image view?


how to set a text over an imageView?


Display TextView over ImageView in android


Text to Image in android


How to create the gallery folder in android programmatically?


Rss parser android with text on image



Strange out of memory issue while loading an image to a Bitmap object


Get screen dimensions in pixels


Close/hide the Android Soft Keyboard


Android: combining text & image on a Button or ImageButton


Why is the Android emulator so slow? How can we speed up the Android emulator?


Stop EditText from gaining focus at Activity startup


How to make an ImageView with rounded corners?


Is there a unique Android device ID?


findViewById in Fragment


Proper use cases for Android UserManager.isUserAGoat()?

Hot Network Questions

  • Is it acceptable to publish student names with the label ‘stupid question’, on a publicly-visible website?

  • Isn’t supervisor bound to teach for saving time?

  • Are there mistakes on the pre-rolled Basic Set wizard and ranger character sheets?

  • Manipulating text in first column only?

  • Unique filtered index and surprising estimation

  • How to disable the "website is now full screen" warning in Firefox?

  • With Jeremy Crawford taking over Acquisitions, Inc, will his rulings on the show be considered RAW?

  • Could/Should I cite a paper that I am refereeing?

  • Book about old man storing magical power into plates

  • Will the United Nations global compact on migration make it a criminal offense to criticize migration?

  • Is it possible that the return ticket of a round-trip is counterfeit?

  • Use columns 1 and 2 to populate column 3

  • Printing every 10th result in an alternating ± series

  • The math behind Warren Buffet’s famous rule – never lose money

  • Our product is ruining users privacy, without telling them

  • What if a law is literally impossible to follow?

  • Maybe u should investigate carefully?

  • Trifid Cipher (without keyword)

  • How powerful would an always-on Truesight ability be for a PC?

  • Non scalable unit in tikz

  • Have spelling reformers ever proposed rewriting "-ti-" as "-zi-" when it is pronounced that way?

  • Units in group rings.

  • What to teach after scales and chords

  • Word for repetition of a same word before and after comma?

more hot questions

question feed


Stack Overflow works best with JavaScript enabled

Grafix Artist

Thoughts on Mobile App Design and Development


  • Design

Design Techniques to Display Text over Background Images

· Updated

It’s become popular to overlay text labels on background images. But the image could be anything. How does your user interface design accommodate that? Can text overlay remain readable always?

The last thing you’d want is your users straining to read such text. This is all the more important on mobile. Smaller screens and smaller text make it slightly harder to read.

But don’t worry. There are a couple of design techniques you can follow to ensure that.


First, let me show you some design mockups that use text overlay.

Photography Portfolio by Winart Foster on Dribbble

Here’s another.

Article Cards Alternate by Oliur on Dribbble

A good eye will immediately notice the problem with these two designs. Take the second one with the sea waves. If the wave foam was on the lower half of the image, would that text be readable?

Let me try to recreate that design for you.

Text with scrim overlay

How readable is the text now?

Alright, its not the same picture. But it’s still ocean waves.

The background image is outright disturbing. But the image is not to blame. After all, when you decide to overlay text, you must be ready for ANY image. Which means, the image could be anything.

Good design is when we factor in all possible scenarios.

Now don’t get me wrong. Those 2 designs are not bad in any way. In fact, I love the typography used in the second one. Both are well-designed interfaces by talented people. It’s just that, some interface designs (mockups) are only for aesthetic purposes.

Anyone who translates them into a working project will immediately recognize what’s wrong. The text displayed, does not account for its background images.

However these mockups are only examples. It assumes that whatever be the image, the text will be readable. But my design attempt just showed you that that’s not the case.

The 2-in-1 problem with text overlay

Now we could say that this pattern became overly popular thanks to Card design. I mean, most of the card designs include an image, with text overlaid on top. Not to say that its bad, but there are two things that are largely not considered.

Trip detail card by Harsheen Kaur

When you overlay text on an image, you sacrifice two things:

  1. Image clarity
  2. Text readability

Readability is the ease with which a reader can understand a written text. It is a measure of how easily a reader can distinguish individual letters or characters from each other. – Wikipedia

Overlaying a text prevents viewing the image completely. Moreover, your text may not be readable.

The image can be anything

Now, most of the examples above are mockups. Which means those are ideal scenarios. The text matches perfectly against its background. Things can immediately go wrong if your using white text over a whitish or light image. The same holds true for black or darker tones.

Now we know the mess we’re getting ourselves into. So let’s look at what we can do about it.

Text Overlay Solutions

There are different approaches to making our overlay text readable. I want you to understand that these are different solutions to a single problem. There is no single solution answer.

Moreover, deciding on what to use ultimately boils down to your personal preference. Or you can even decide upon one, depending on what fits your brand style.

1. Using a Scrim

A Scrim is a semi-transparent gradient layer that helps Text appear more readable against backgrounds.

A scrim is a solid to a transparent gradient that sits behind a Text Label. So for instance, your text label could be a constant white. Then, your scrim would be a gradient going from, say 40% black to transparent.

I leave the opacity percentage to you. Again that’s a matter of personal taste.

But a 40% black to transparent works really well. It’s not too evident and doesn’t disturb the image. It fades smoothly, giving the text label the contrast it needs, making it readable.

Scrim – gradient overlay

Recommended Scrim guidelines:

  • 40% opacity
  • gradient settings
  • height: 50% of image height

These are not hard rules. But as you can see from the above design, these settings work well.

You can read about this in the  Material Design Imagery guidelines .

Scrim gradient settings in Sketch


  • Most simple and common solution
  • Increases contrast for better text readability
  • A subtle design change which is hardly noticeable


  • Sharp gradients can break the image’s appeal
  • Can block the image if visibility is too high

By far, using a scrim is the most popular solution for solving the text overlay issue with images.

But wait, don’t go yet! There are other solutions which might suit your taste better.

2. Overlay the entire image

Like the scrim solution, and instead of a gradient, you’d apply a full 40% black to the whole image.

That’s right. Maybe the image isn’t important to you. The text label is your priority. Or maybe the text covers the entire image’s size.

In such a situation, using a scrim doesn’t make sense. Since the scrim is a gradient, your text becomes unreadable half-way across.

So since the text covers the whole image, the solution is to darken the entire image.

In short, that’s a 40% opacity black on the image.


  • Useful for large text (headings?) that covers the entire image
  • When text is your priority and not the image


  • Can obscure the entire image
  • Could sacrifice image visibility
  • Can diminish the background image as if it exists only for aesthetics

Here are some popular apps that use this approach:

Medium Series on Android


85000+ Status and Quotes 2017 Android App by Pratik Butani

3. Color Overlay

This is like an overlay. But instead of using black or white to darken or lighten the image, we use a different color.

Setting a color overlay on an image is the perfect way to neutralize a busy image. It blocks out all the different colors, making the image monotone.

Usually, the color of choice is the brand color.

Here is an example.

Playgong App by Deividas Graužinis

4. Soft gradients

Remember that to use this correctly, your text should have enough contrast.

Also, when you use gradients, don’t use visually jarring colors. Chose colors that work together in harmony.

You can use web tools such as  Coolors and Kuler by Adobe . These can help you generate color pairs that work well together.

Here’s an example.

Web Agency by Mohammad Shohag


  • Better brand emphasis (if brand color used)
  • Single color tone allows room for better text contrast


  • Not suitable for pictures of people as it may not be recognizable

5. Semi-Transparent Image

This technique involves using a semi-transparent image against a solid color background. It helps ‘calm’ the noisy background, so the text can stand out.

The technique consists of 3 layers (from the bottom):

  1. Bottom – solid color
  2. Middle – semi-transparent image (40% opacity)
  3. Top – Text layer


  • Softer image allows text to stand out
  • Makes image monotone, reducing image noise


  • Image may lose important details
  • Only suitable for images whose purpose is eye candy

6. Blur

Applying a Gaussian blur softens an image allowing text to become more readable.

Smoothing of images by reducing image noise and detail – Gaussian Blur

iOS folks will be familiar with this technique. iOS design principles use blur to denote depth. Whereas Android (Material Design) uses shadows to denote depth (elevation).

Here’s a 16px blur on the left, and 4px blur on the right. Make sure you don’t blur the image too much that the underlying image is completely unrecognizable!

Blur doesn’t solve same text and image color problem


  • Helps reduce the ‘busyness’ in images
  • Softened images allow text to stand out


  • Completely sacrifices the image for text
  • Still doesn’t solve same-color overlay issue
  • May not suit your product style. Using blur in a Material Design world?

7. Text Highlight

Here, we apply a background color to the text itself. This effect mimics the traditional way of highlighting text on paper.

Text with Highlighter effect

This technique works well when the design has minimal text and a spacious background.

Remember that the highlight color doesn’t always have to be black. The example on the right borrows the dominant color from the image. This creates a higher sense of belonging with the image.


  • Good text clarity against any background image
  • Good contrast


  • Choice of highlight color may make text feel disconnected from image
  • Can completely block the underlying image

8. Go Grayscale

Alright, this is more of altering the image than the text. But we can still use it to achieve what we want.

By using a grayscale image.

Greyscale image filter

However, remember that greyscale includes colors from the brightest white to the darkest black. These alone, are on the polar ends of vibrancy. Hence you might want to consider toning down the image first. You can do so via a mix and match with any other techniques mentioned here.

For example, here’s a grayscale image with text at the bottom. However, by default this wouldn’t look good. So we add a scrim at the bottom.

Greyscale image with bottom Scrim combined

Notice how the scrim naturally blends very well with the image. The image is greyscale and our scrim is a black to transparent gradient. Hence the two techniques go hand-in-hand, quite well.

9. Playing with color and positioning

Sometimes, no matter what, the image remains the same. Say, for example, a category page will use a constant header image depicting its category.

In such a situation, you know what image to expect. You can use this information to design your text. This can be the font, size, color or even positioning the text.

Universitet Modules by Flatstudio

Notice the smart positioning of text, away from images. Also, the calm pastel background colors are not distracting. Both work in favor of allowing the text to stand out in addition to the graphic.

TL;DR – Use enough contrast

The state of being strikingly different from something else in close association. – Contrast

Did you notice? All the techniques discussed above are ways to increase text contrast. Contrast is what makes an element appear distinct from one another. There should be high contrast between text and image. It allows text to be readable.

There is also no need to sacrifice image visibility for text. Both can coexist together if we use the right technique. For instance, using a scrim allows text to be readable. At the same time, the image is visible as well.

As a general rule, using greyscale colors work well. Which means, white text against a dark background. Or black (dark grey) text against a light background always works best.


We looked at techniques that make text readable, without sacrificing the background image. Techniques such as the scrim are perfect examples of this. Or, using a color overlay can help reinforce your brand by using its primary color. This is especially useful when the image feels out of place in your design. Moreover, the blur technique is useful as well. But you will have to see if it aligns with your design style.

Remember that good design is thoughtful and knows how to balance aesthetic visuals with usability and clarity. It is not enough to let people use your app. It must be easy and pleasing to use.

You can even mix and match two techniques. Your imagination is the limit. Color overlay with scrim anyone?

So which technique are you going to use? Have I missed any popular method? I’d love to hear your thoughts. Let’s talk in the comments below.

Subscribe to stay updated
You’ll be first to know about new articles and more. They’re sent straight to your inbox!

No Spam, no BS. Promise. You can unsubscribe anytime.


App developer with an eye for design. Loves to create apps with good UI/ UX that doesn’t annoy people. In his spare time, he likes to draw and paint.

Tags: background design header image overlay readability text UI usability user experience user interface UX


App developer with an eye for design. Loves to create apps with good UI/ UX that doesn’t annoy people. In his spare time, he likes to draw and paint.

  • Next story Android Image Gallery App: Using Gestures and Transition
  • Previous story Android O Tutorial: Using Custom Font Resources

You may also like…

  • How To Design A Great Mobile App Intro By Learning From The Best

    · Published July 2, 2018
    · Last modified December 1, 2018

  • Circular Reveal Effect like WhatsApp in Android

    · Published July 17, 2015
    · Last modified February 14, 2017

  • design cubes

    Why app design is important

    · Published April 14, 2015
    · Last modified February 23, 2017


  • Toolbar Animation-Flexible Space with Image
  • Material Design Tab Layout
  • Easy Material Navigation Drawer
  • Parallax Scrolling Tabs with Header Image
Learn React Native to build Android & iOS apps faster

Recently Updated

  • Android O: Getting Started (Developer Edition)
  • Managing Fragments with Bottom Navigation
  • Android O: Using Custom Fonts
  • Parallax Scrolling Tabs with Android Design Support Library


  • Material Design Components for Android
  • Pagination with RecyclerView
  • Top 10 Material Design Libraries

Subscribe to stay updated
You’ll be first to know about new articles and more. They’re sent straight to your inbox!

No Spam, no BS. Promise. You can unsubscribe anytime.

Download FREE


Material Design Template Project for Android Studio