Skip to content
Related Articles

Related Articles

How to Create Marquee Text in Android?

View Discussion
Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 31 Mar, 2021

In this article, we are going to create Marquee Text in Android Studio. Marquee is a scrolling piece of text that is displayed either horizontally or vertically. It is used to show some important notice or headlines. It makes app UI much attractive. Note that we are going to use Java as the programming language. A sample GIF is given below to get an idea about what we are going to do in this article.

Create Marquee Text in Android Sample GIF

Step by Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that you have to select Java as the programming language. 

Step 2: Working with the activity_main.xml file

Navigate to the app > res > layout > activity_main.xml and add the below code to that file. TextView is used here to add the text which we want to display on the screen. Here we have used android:ellipsize=”marquee” to add a marquee to our text and android:singleLine=”true” so that our text will show only in one line. Also, we have used android:marqueeRepeatLimit=”marquee_forever” so that marquee will repeat infinitely and one more attribute that I have used here is android:scrollHorizontally=”true” so that text will scroll horizontally.        


<?xml version="1.0" encoding="utf-8"?>
    Textview is used here to add the text which we want to display on the screen.Here important attributes are:
    i)   android:singleLine="true"... so that our text will show only in one line
    ii)  android:ellipsize="marquee"... to add marquee to our text
    iii) android:marqueeRepeatLimit="marquee_forever" that marquee will repeat infinitely
    iv)  android:scrollHorizontally="true"... so that text will scroll horizontally
        android:text="Hello guys !! Welcome to GeeksforGeeks Portal !!"
        android:textStyle="bold" />

Step 3: Working with the file

Go to Class. We have called the setSelected() method and passing the boolean value as true so that our marquee will get started. Below is the code for the file.


import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
    TextView txtMarquee;
    protected void onCreate(Bundle savedInstanceState) {
        // casting of textview
        txtMarquee = (TextView) findViewById(;
        // Now we will call setSelected() method
        // and pass boolean value as true

Step 4: Working with colors.xml file

Navigate to the app > res > values > colors.xml. You can add as many colors as you need for your app. You have to just give a color code and put the color name. In this app, we have kept the app bar color as green with the color-code “#0F9D58”. 


<?xml version="1.0" encoding="utf-8"?>
    <color name="Green">#0F9D58</color>
    <color name="purple_500">#FF6200EE</color>
    <color name="purple_700">#FF3700B3</color>
    <color name="teal_200">#FF03DAC5</color>
    <color name="teal_700">#FF018786</color>
    <color name="black">#FF000000</color>
    <color name="white">#FFFFFFFF</color>

Step 5: Working with themes.xml

Navigate to the app > res > values > themes.xml and choose the theme of your choice. We have used parent=”Theme.MaterialComponents.DayNight.DarkActionBar” that is DayNight theme with dark ActionBar. You can add parent=”Theme.AppCompat.Light.DarkActionBar” to get light theme with dark action bar and parent=”Theme.AppCompat.Light.DarkActionBar” for light theme with dark action bar.


<resources xmlns:tools="">
    <!-- Base application theme. -->
    <style name="Theme.MarqueeText"
        <!-- Primary brand color. -->
        <item name="colorPrimary">@color/Green</item>
        <item name="colorPrimaryVariant">@color/Green</item>
        <item name="colorOnPrimary">@color/white</item>
        <!-- Secondary brand color. -->
        <item name="colorSecondary">@color/teal_200</item>
        <item name="colorSecondaryVariant">@color/teal_700</item>
        <item name="colorOnSecondary">@color/black</item>
        <!-- Status bar color. -->
        <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
        <!-- Customize your theme here. -->

Step 6: Working with strings.xml

Navigate to the app > res > values > strings.xml. Here you can add an app bar title. We have set “GFG | MarqueeText” as a title.


    <string name="app_name">GFG | MarqueeText</string>


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!