<TextView android:id="@+id/btn_update" style="@style/item_show_title" android:ellipsize="marquee" android:layout_weight="1" android:focusable="true" android:focusableInTouchMode="true" android:marqueeRepeatLimit="marquee_forever" android:singleLine="true" android:text="000000"/> 会导致settext失效吗
时间: 2023-07-06 18:07:17 浏览: 56
这段代码不会导致 `setText` 失效。但如果你想让 `setText` 生效,你需要禁用 `android:ellipsize`,因为它会截断文本并添加省略号。此外,如果你想让文本滚动,你可以通过在代码中设置 `setSelected(true)` 来实现,而不是使用 `android:marqueeRepeatLimit` 和 `android:singleLine` 属性。最后,如果你想让 `TextView` 可以获取焦点并接收键盘输入,你可以将 `android:focusable` 和 `android:focusableInTouchMode` 属性设置为 `true`。
相关问题
<TextView android:id="@+id/areaTotalHit" style="@style/item_show_title" android:layout_width="wrap_content" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" android:marqueeRepeatLimit="marquee_forever" android:singleLine="true" android:text="实际库存:" /> <TextView android:id="@+id/btn_update" style="@style/item_show_title" android:ellipsize="marquee" android:layout_weight="1" android:focusable="true" android:focusableInTouchMode="true" android:marqueeRepeatLimit="marquee_forever" android:singleLine="true" android:text="0"/>改为默认字体
你可以在style中定义一个默认字体的属性,然后将这两个TextView的style改为该属性。例如:
在styles.xml中添加:
```xml
<style name="AppTheme.DefaultFont">
<item name="android:fontFamily">@font/your_default_font</item>
</style>
```
然后将这两个TextView的style改为该属性:
```xml
<TextView
android:id="@+id/areaTotalHit"
style="@style/AppTheme.DefaultFont"
android:layout_width="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:text="实际库存:" />
<TextView
android:id="@+id/btn_update"
style="@style/AppTheme.DefaultFont"
android:ellipsize="marquee"
android:layout_weight="1"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:text="0"/>
```
注意,你需要将`@font/your_default_font`替换为你自己的默认字体。
<TextView android:id="@+id/title" style="@style/text_18_ffffff" android:layout_width="fill_parent" android:layout_height="40.0dip" android:gravity="center" android:text="已盤點商品" android:visibility="visible" />加入渐变色
你可以在 TextView 的背景属性中使用 GradientDrawable 来实现渐变色。以下是一个示例代码:
```xml
<TextView
android:id="@+id/title"
style="@style/text_18_ffffff"
android:layout_width="fill_parent"
android:layout_height="40.0dip"
android:gravity="center"
android:text="已盤點商品"
android:visibility="visible"
android:background="@drawable/gradient_background" />
```
其中,@drawable/gradient_background 是一个定义了渐变色的 Drawable 文件。以下是一个 gradient_background.xml 文件的示例代码:
```xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#FF0000"
android:endColor="#00FF00"
android:type="linear"
android:angle="45" />
</shape>
```
这个示例定义了一个线性渐变的 Drawable,起点颜色为红色,终点颜色为绿色,角度为 45 度。你可以根据自己的需求修改颜色和角度。