java - 文本选取框不起作用

标签 java android eclipse user-interface textview

请看下面的代码

<TableRow
          android:id="@+id/tableRow13"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:padding="5dp" >

            <TextView
                 android:id="@+id/textView22"
                  android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:textColor="#ffffff"
                 android:textSize="12sp"
                 android:text="@string/r_new_event"
                 android:layout_marginLeft="5dp"
                 android:textAppearance="?android:attr/textAppearanceSmall" />

             <TextView
                 android:id="@+id/textView23"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="Meeting with people i have never seen before in my entire life lol"
                 android:ellipsize="marquee"
                 android:maxLength="10"
                 android:singleLine="true"
                 android:fadingEdge="horizontal"
                 android:marqueeRepeatLimit="marquee_forever"
                 android:scrollHorizontally="true"
                 android:textColor="#ffffff"
                 android:textSize="12sp"
                 android:layout_marginLeft="10dp"
                 android:textAppearance="?android:attr/textAppearanceSmall" />

</TableRow>

此尝试是在文本长度超过 10 个字母时对文本进行选取框显示。但不幸的是,这段代码不起作用。我在moth模拟器和Android手机上尝试过。这里出了什么问题?

更新

以下是我的新代码,它仍然无法工作

<TextView
    android:id="@+id/textView23"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Meeting with people i have never seen before in my entire life lol"
    android:ellipsize="marquee"
    android:maxLength="10"
    android:singleLine="true"
    android:fadingEdge="horizontal"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true"
    android:textColor="#ffffff"
    android:textSize="12sp"
    android:layout_marginLeft="10dp"
    android:focusable="true" 
android:focusableInTouchMode="true" 
    android:freezesText="true"
    android:textAppearance="?android:attr/textAppearanceSmall" />

最佳答案

试试这个代码..

XML

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:id="@+id/mywidget"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:lines="1"
        android:ellipsize="marquee"
        android:fadingEdge="horizontal"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:textColor="#ff4500"
        android:text="Simple application that shows how to use marquee, with a long text" />
</RelativeLayout>

主要 Activity

public class TextViewMarquee extends Activity {
    private TextView tv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tv = (TextView) this.findViewById(R.id.tv);  
        tv.setSelected(true);  // Set focus to the textview
    }
}

关于java - 文本选取框不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19658586/

相关文章:

Eclipse Maven 依赖项未找到

Java 库文件错误

c++ - eclipse CDT : How to manage multiple main() functions in a single C++ project?

java - 如何在Spring中更改Application.properties的值

android - 当我没有注册任何接收者时,Activity 泄露了 IntentReceiver

java - SoundPool 和 MediaPlayer 中的并发性?

Android libc.so 崩溃?

java - 如何在 ftp4j 库中使用 SSL

java - 如果有父级,Quarkus 不会构建

java - 在抽象类定义中使用 2 级泛型