So I have a LinearLayout then inside is a ScrollView then inside is another RelativeLayout and finally inside is another LinearLayout with id mylinearlayout.
I want to create TextView's dynamically it works fine, but the text seems to be disabled like GRAY color. Although i didn't set any color..
Here's my code:
final LinearLayout linlayout = (LinearLayout) findViewById(R.id.mylinearlayout);
final TextView tv = new TextView(getApplicationContext());
tv.setTextSize(20);
tv.isEnabled();
tv.setGravity(Gravity.CENTER);
if(orderstatus.equals("Pending")) {
tv.setText("OrderID: "+orderid + "\n"+"OrderDate: " + orderdate + "\n" +"OrderStatus: "+orderstatus + " \n\n");
tv.setId(i + 5);
linlayout.addView(tv);
}
Use this code
linlayout = (LinearLayout) findViewById(R.id.mylinearlayout);
TextView tv = new TextView(getApplicationContext());
tv.setTextSize(20);
tv.isEnabled();
tv.setGravity(Gravity.CENTER);
if(orderstatus.equals("Pending"))
{
tv.setText("OrderID: "+orderid + "\n"+"OrderDate: " + orderdate + "\n" +"OrderStatus: "+orderstatus + " \n\n");
tv.setId(i + 5);
tv.setTextColor(Color.BLACK);
linlayout.addView(tv);
}
You doing well, but miss one moment. When you add view into layout, view automaticly sets color from current system styles. If you need to change color of your text, do this:
tv.setTextColor(YOUR_COLOR);
Your TextView text may grey because it's using the system Theme rather than your Activity's. You could try passing this instead of getApplicationContext() in your TextView() constructor. This is true for Toast objects, for example, and may also apply to widgets.
Related
I am displaying text in a textview without using toString(), to keep the formatting(bold, underline, italics) within the text. But now I want to set different font sizes to _etheadertext ,_etheadertext3 etc..
String header = _etheadertext.getText() + "\n" + _etheadertext3.getText() + "\n" + _etheadertext4.getText() + "\n" + _etheadertext5.getText();
You can use text Spans to apply formatting to parts of a string.
SpannableString spannablecontent=new SpannableString(content.toString());
//set a Style Span to apply Typeface style
spannablecontent.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC),
0,spannablecontent.length(), 0);
You can set RelativeSizeSpan to change the text sizes if required.
And then finally, set the spanned string in a TextView.
mTextView.setText(spannablecontent);
I am trying to take a string (which is formatted HTML) and split it at every double enter. I know that before and after a double enter will be a p block tag, and I'm using a for loop to split it in this way. Here is my code
for(String s : rawHTML.split("\\n\\n")){
View newView = LayoutInflater.from(c).inflate(R.layout.commentandunder, baseView, true);
LinearLayout underneath = (LinearLayout) newView.findViewById(R.id.inside);
TextView comm = (TextView) newView.findViewById(R.id.commentLine);
Log.v("Slide", "Should be " + s );
Log.v("Slide", "Currently is "+ comm.getText());
comm.setText(Html.fromHtml(s) );
Expected behavior from this is every "Currently is" in the log should be blank. If there are two or more p blocks, though, when I setText, it overwrites the previous text.
For example, I have a string
<p>Test</p>\n\n<p>Hello</p>
I should be seeing two TextViews like so
[Test]
[Hello]
Instead, I see this
[Hello]
[]
I am really stumped and can't figure out this strange issue.
Thank you!
The following code snippet shoud work for you.
View newView = LayoutInflater.from(c).inflate(R.layout.commentandunder, baseView, true);
LinearLayout underneath = (LinearLayout) newView.findViewById(R.id.inside);
TextView comm = (TextView) newView.findViewById(R.id.commentLine);
Log.v("Slide", "Should be " + s );
Log.v("Slide", "Currently is "+ comm.getText());
for(String s : rawHTML.split("\\n\\n")){
comm.append(Html.fromHtml(s) );
}
How do you show two values on different lines using a single testview? I can get this by using two textviews but I want to show values in a single textview. What should I d0?
xmlRespone[3][1]= Salman Ahmed
xmlRespone[4][1]= 435000;
TextView lblWelcome = (TextView) findViewById(R.id.lblWelcome);
lblWelcome.setText("Welcome " + xmlRespone[3][1]);
TextView lblYouraccountbalance = (TextView)
findViewById(R.id.lblYouraccountbalance);
lblYouraccountbalance.setText(" balance :" + xmlRespone[4][1]);
Try "\n" for new line.
TextView lblWelcome = (TextView) findViewById(R.id.lblWelcome);
lblWelcome.setText("Welcome " + xmlRespone[3][1] + "\n" + xmlRespone[4][1]);
Output : Welcome Salman Ahmed
435000
So is it possible to change text size of part of the text in textview dynamically
Let's say we have a method that does that...what am I missing...I want to make x variable twice as big as y...they are string btw...
private void Data_transfer() {
test3.setText( x + " " + y);
}
You can use the Spannable type with a TextView to set multiple styles in one field.
In your case, you can do this like so, using the fromHtml() method which generates a Spannable string:
test3.setText( Html.fromHtml( "<font size='10'>" + x + "</font> <font size='5'>" + y + "</font>" ) );
And you can, of course, change 10 and 5 to whatever values you like.
private void Data_transfer() {
TextView tv = (TextView)findViewById(R.id.textView1);
tv.setText("Welcome to android");
}
I have been developing a game with opengles for android and have a glsurfaceview displayed. I also have a textview displayed over this by using
addContentView(mytextview, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT) );
mytextview contains a string which is made up of a string plus the parsed value of an int. eg something like
mytextview = new TextView(this);
mytextview.setText("Score: " + Integer.toString(score) );
The textview and the integer value display but
My question is how do I update this when the integer value changes?
you'll have to call mytextview.setText("Score: " + Integer.toString(score) );
every time the score changes.