textview

How to get line count of textview before rendering?

[亡魂溺海] 提交于 2020-01-09 09:06:07
问题 How can I get the number of lines a string will take up in a TextView before it is rendered. A ViewTreeObserver will not work because those are only fired after it is rendered. 回答1: final Rect bounds = new Rect(); final Paint paint = new Paint(); paint.setTextSize(currentTextSize); paint.getTextBounds(testString, 0, testString.length(), bounds); Now divide the width of text with the width of your TextView to get the total number of lines. final int numLines = (int) Math.ceil((float) bounds

How to get line count of textview before rendering?

天涯浪子 提交于 2020-01-09 09:04:07
问题 How can I get the number of lines a string will take up in a TextView before it is rendered. A ViewTreeObserver will not work because those are only fired after it is rendered. 回答1: final Rect bounds = new Rect(); final Paint paint = new Paint(); paint.setTextSize(currentTextSize); paint.getTextBounds(testString, 0, testString.length(), bounds); Now divide the width of text with the width of your TextView to get the total number of lines. final int numLines = (int) Math.ceil((float) bounds

How to get value from TextView in android?

倾然丶 夕夏残阳落幕 提交于 2020-01-07 09:58:30
问题 I'd like to make a simple share button to get a TextView value and share it, but I don't know how to do that. Here is the code: public class DetailActivity extends AppCompatActivity { Button shareBtn ; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_detail); try{ String key = getIntent().getStringExtra("key"); String value = getIntent().getStringExtra("value"); TextView title = (TextView) findViewById(R.id

How to get value from TextView in android?

放肆的年华 提交于 2020-01-07 09:58:22
问题 I'd like to make a simple share button to get a TextView value and share it, but I don't know how to do that. Here is the code: public class DetailActivity extends AppCompatActivity { Button shareBtn ; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_detail); try{ String key = getIntent().getStringExtra("key"); String value = getIntent().getStringExtra("value"); TextView title = (TextView) findViewById(R.id

GradientDrawable with OVAL shape not working inside programatically added Text View

房东的猫 提交于 2020-01-07 09:44:31
问题 I have programmatically added Text View and Button . Code final TextView test = new TextView(getApplicationContext()); test.setText(String.valueOf(counterQuantity)); test.setTextColor(getResources().getColor(R.color.black)); test.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10); GradientDrawable border = new GradientDrawable(); border.setShape(GradientDrawable.OVAL); border.setStroke(1, getResources().getColor(R.color.black)); border.setCornerRadius(2); border.setColor(getResources().getColor(R

GradientDrawable with OVAL shape not working inside programatically added Text View

别说谁变了你拦得住时间么 提交于 2020-01-07 09:43:05
问题 I have programmatically added Text View and Button . Code final TextView test = new TextView(getApplicationContext()); test.setText(String.valueOf(counterQuantity)); test.setTextColor(getResources().getColor(R.color.black)); test.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10); GradientDrawable border = new GradientDrawable(); border.setShape(GradientDrawable.OVAL); border.setStroke(1, getResources().getColor(R.color.black)); border.setCornerRadius(2); border.setColor(getResources().getColor(R

ImageSpan Size Measurement with TextView and StaticLayout

北战南征 提交于 2020-01-07 06:24:34
问题 I have a simple layout contains just one TextView . I wanna load an image into TextView using ImageSpan. Below method creates Spannable : private Spannable getImageSpannable(int drawableId, int targetWidth, int targetHeight) { Bitmap originalBitmap = BitmapFactory.decodeResource(getResources(), drawableId); Bitmap bitmap = Bitmap.createScaledBitmap(originalBitmap, targetWidth, targetHeight, true); Drawable dr = new BitmapDrawable(getResources(), bitmap); dr.setBounds(0, 0, bitmap.getWidth(),

how can I disable the changable TextView and click on it reenable the button?

让人想犯罪 __ 提交于 2020-01-07 05:42:09
问题 Hey I have a button keyboards with green picture if the user press on it disable it(red color) and print it on the text view I have 4 textview so step by step the 4 text view fill the last textview doesn't stand and it's own number its changes every time I press on another enable number how can i disable this and I want when I click on every textview to delete the number in it and reenable the number that was in it and for example i choose second txt2 and i cleared it by click on it by

Android TextView

橙三吉。 提交于 2020-01-07 05:14:06
问题 I have an example in android that I am trying to run. There were 2 ways to do it.. // Get a drawable ColorDrawble redDrawable = (ColorDrawable).getResources().getDrawable(R.drawable.red_rectangle); //Set it as a background to a text view textView.setBackground(redDrawable); When I put this in the Eclipse IDE I get an error ColorDrawble cannot be resolved to a type I have the textview in the main XML <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com

Android Adding more than one TextView to a TableRow Programmatically

折月煮酒 提交于 2020-01-07 04:21:43
问题 I have a LinearLayout inside a FrameLayout for tab purposes. And I'm trying to add TableRow's to the LinearLayout in the code. LinearLayout testLayout = (LinearLayout)findViewById(R.id.testLayout); TableRow tableRow = new TableRow(this); tableRow.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT)); This gets my LinearLayout and creates a TableRow to the specifications I want. I know this part is working. TextView textOne = new TextView(this); textOne