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);
Tracking Valuable Threads from Worldwide Discussion Boards for Android Enthusiasts and Programmers
Showing posts with label Textview. Show all posts
Showing posts with label Textview. Show all posts
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!
I also have this file (colors.xml) in my res/values folder
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:
// 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);
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.
Subscribe to:
Comments (Atom)
Popular Posts
-
Trying to found out how to enable "diagnostic" mode on an HTC Android device, specifically a T-Mobile G2 / HTC Desire Z. In my sea...
-
Does anyone know information about how to connect the Samsung Fascinate as Diag Mode driver? ie: this type of connection needed for QPST/QX...
-
Even a basic program that can encrypt and decrypt SD card, at least the external SD card would be acceptable. This way we can be assured tha...
-
Joikuspot is a program for Symbian that bridges the WiFi and 3G connection so the phone acts as a hotspot for wireless connection. I figure ...
-
On Android phones SMS messages registered to applications also get sent to the device's inbox. However to prevent clutter, it'd be n...
-
I decided to wipe all data by turning the phone off and then pressing the home key and the power key. From there it went to the recovery men...
-
I am brand new to cell phones so please excuse the very basic questions and problems I am having. I am trying to get QPST to work with my Sp...
-
Go to: 1. Settings 2. Applications 3. Manage Applications 4. Select Filter 5. Select All 6. Select "Maps" application. It w...
-
I'm getting this error from time to time and don't know what causing this: When trying to run/debug an Android app on a real devic...
-
What is the best GPS application usable without an Internet connection? (Android) I don't use it by car, just for walking in cities. I...