我是 android 的新手,我正在开发一个制卡应用程序。我想在应用程序中添加一项功能,使用户能够将背景颜色应用于全宽的textView。我需要它像下面的图像:
当文本长度很长时,这可以正常工作,但是当文本包含多行而不是全宽时,它就像下面的图像:
无论文本多长,我都需要与第一张图像相同的结果。在textView中,我使用 wrap_content 作为高度和宽度。即使textView只有字母A,我也需要以完整的显示宽度对textview应用背景。我希望它清楚。感谢
答案 0 :(得分:1)
textview.setBackgroundColor(Color.parseColor("#FF0000"));
答案 1 :(得分:1)
示例代码:
<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="Some Text"
android:background="#424242" />
答案 2 :(得分:1)
尝试将textview
宽度设置为match_parent.
android:layout_width: - &gt; 指定视图的基本宽度。
示例代码
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
或以编程方式设置textview的LayoutParams
LayoutParams My_params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1f);
textview.setLayoutParams(My_params);
答案 3 :(得分:1)
试试这个:
{868: ['S00086', 640.8, 38.45], 869: ['S00087', 476.31, 28.580000000000002]}
答案 4 :(得分:0)
设置 textview width match_parent。
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
答案 5 :(得分:0)
尝试从&#34; wrap_content&#34;更改TextView的宽度。 to&#34; match_parent&#34; :
<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>