Showing posts with label Textview. Show all posts
Showing posts with label Textview. Show all posts

Android - Making TextView Scrollable

I am displaying text in a textview that appears to be too long to fit into one screen. I need to make my TextView scrollable. How can i do that? Here is the code final TextView tv = new TextView(this);

tv.setBackgroundResource(R.drawable.splash);
tv.setTypeface(face);
tv.setTextSize(18);
tv.setTextColor(R.color.BROWN);

tv.setGravity(Gravity.CENTER_VERTICAL| Gravity.CENTER_HORIZONTAL);

tv.setOnTouchListener(new OnTouchListener(){


public boolean onTouch(View v, MotionEvent e)
{

Random r = new Random();
int i = r.nextInt(101);

if (e.getAction() == e.ACTION_DOWN)
{
tv.setText(tips[i]);
tv.setBackgroundResource(R.drawable.inner);

}

return true;
}

});

setContentView(tv);

Android - TextView setting the background color dynamically doesn't work

Setting the background color programatically of an android TextView doesn't seem to work. I'm I missing something!

TextView et = new TextView(activity); 
et.setText("350"); 
et.setBackgroundColor(R.color.white); 

I also have this file (colors.xml) in my res/values folder
 
<resources> 
        <color name="white">#ffffffff</color> 
        <color name="black">#ff000000</color> </resources> Also, setting the text color causes the TextView to disappear.
 
TextView c1 = new TextView(activity); 
c1.setTextColor(R.color.solid_red); 
c1.setText("My Text"); 

Android - Multiple styles inside a TextView

I was wondering if its possible to set multiple styles for different pieces of text inside a TextView. For instance, I am setting the text as follows:descbox.setText(line1 + "\n" + line2 + "\n" + word1 + "\t" + word2 + "\t" + word3);

Now, is it possible to have a different style for each text element? I mean bold for line1, normal for word1 and so on...

I found this http://developer.android.com/guide/appendix/faq/commontasks.html#selectingtext: // Get our

EditText object.But it uses position numbers inside the text. Is there a cleaner way to do this? EditText vw = (EditText)findViewById(R.id.text);
 
// Set the EditText's text.
vw
.setText("Italic, highlighted, bold.");
 
// If this were just a TextView, we could do: // vw.setText("Italic, highlighted, bold.", TextView.BufferType.SPANNABLE); // to force it to use Spannable storage so styles can be attached. // Or we could specify that in the XML.
 
// Get the EditText's internal text storage Spannable str = vw.getText();
 
// Create our span sections, and assign a format to each.
str
.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, 7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
str
.setSpan(new BackgroundColorSpan(0xFFFFFF00), 8, 19, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
str
.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 21, str.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 

Android - How to center text horizontally and vertical in a TextView?

How to center text horizontally and vertical in a TextView in Android? So that it appears exactly in the middle of the screen.


Popular Posts