Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8195543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:10:26+00:00 2026-06-07T05:10:26+00:00

Refering agradient to textview regard as normal action can be achieved in android ,

  • 0

Refering agradient to textview regard as normal action can be achieved in android ,

as below :

 android:background="@drawable/gredient"

and gradient XML will be as below code :

<?xml version="1.0" encoding="utf-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
  <gradient android:startColor="#B22222" android:centerColor="#000000"
          android:endColor="#B22222" android:angle="0" /> 
    <corners android:radius="15dp"  /> 
 </shape>

what im asking about is there is away in android to apply multiple gradients to single textview consisting of may paragraphs , so each paragraph will has different gradient .

any advice will be appreciated ,

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T05:10:27+00:00Added an answer on June 7, 2026 at 5:10 am

    You might want to consider using a WebView instead of TextView (if you need more advanced formatting), but if you want to stick to a TextView, LineBackgroundSpan is your friend 🙂

    Although there might be some better solution (most likely involving a custom Layout-derived class), here’s some sample code that should do what you want just by implementing a special LineBackgroundSpan interface:

    public class MyActivity extends Activity {
    
        private Editable mEditable;
    
        private class MySpan implements LineBackgroundSpan {
            private final Rect rect = new Rect();
            private final Drawable drawable;
            private int next = 0;
    
            public MySpan(Drawable drawable) {
                this.drawable = drawable;
            }
    
            @Override
            public void drawBackground(Canvas c, Paint p, int left, int right, int top, int baseline,
                    int bottom, CharSequence text, int start, int end, int lnum) {
                if (start == end) return;
                if (next == 0) {
                    next = mEditable.nextSpanTransition(start, Integer.MAX_VALUE, MySpan.class);
                    rect.left = left;
                    rect.top = top;
                }
                if (next == end) {
                    rect.right = right;
                    rect.bottom = bottom;
                    c.save();
                    drawable.setBounds(rect);
                    drawable.draw(c);
                    c.restore();
                }
            }
        }
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            final Resources res = getResources();
            final Drawable gd1 = res.getDrawable(R.drawable.gd1);
            final Drawable gd2 = res.getDrawable(R.drawable.gd2);
            final Drawable gd3 = res.getDrawable(R.drawable.gd3);
            final Drawable gd4 = res.getDrawable(R.drawable.gd4);
    
            final TextView tv = new TextView(this);
            setContentView(tv);
    
            tv.setText("Paragraphs with drawable background:\n", BufferType.EDITABLE);
            mEditable = tv.getEditableText();
    
            final String text = "paragraph text ";
            appendPara("###\n".replaceAll("#", text), gd1);
            appendPara("##############\n".replaceAll("#", text), gd2);
            appendPara("#######\n".replaceAll("#", text), gd3);
            appendPara("###########\n".replaceAll("#", text), gd4);
        }
    
        private void appendPara(String string, Drawable gd) {
            final int start = mEditable.length();
            mEditable.append(string);
            final int end = mEditable.length();
            mEditable.setSpan(new MySpan(gd), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am refering to http://developer.android.com/reference/android/app/Activity.html . I have an activity which can be interrupted
I am refering to Using MySurfaceView with main.xml (android) , with the code textView1.setText(set);
I have 2 questions to ask here. I am refering http://www.broculos.net/en/article/android-101-how-create-stackview-widget to create a
$('td.qid').text(). The code above will determine which row the alert is refering to. Below
i've searched through the forum yet i can't find the solution. i'm refering to
I am refering one open source code. There I can found an sql with
Refering to http://www.devx.com/tips/Tip/13291 , it says that I can use memcpy with the size
Hi after refering to http://www.mono-project.com/Embedding_Mono i can call methods from managed code by using
For storing large numbers I am refering to the next: 2.7182818284590455348848081484902650117874145507812500 I can´t save
How can I forward the this scope refering to a element that is calling

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.