简体   繁体   English

具有水平滚动但没有焦点的自定义TextView

[英]Custom TextView with horizontal scroll but without focus

I need a single line Text view, without borders where I can enter the text from my custom buttons. 我需要单行文本视图,没有边框,可以从自定义按钮输入文本。 I do not want to open the soft keyboard, so want this to be non-focusable. 我不想打开软键盘,因此希望它不能聚焦。 It's just as I enter the text through my custom input buttons and that should appear in the Text view along with the cursor at the end of the text. 就像我通过自定义输入按钮输入文本一样,它应该与光标一起显示在“文本”视图的末尾。

I tried using TextView but it does not scroll horizontally as I enter the long text. 我尝试使用TextView,但是在输入长文本时它不会水平滚动。 I want this to scroll to the end of the text. 我希望它滚动到文本的末尾。 If there is longer text, I should be able to scroll manually to view the same. 如果文本较长,我应该可以手动滚动以查看相同的文本。

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:ellipsize="marquee"
    android:focusable="false"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:scrollHorizontally="true"
    android:layout_margin="3sp"
    android:text="@string/empty"
    android:gravity="end"
    android:id="@+id/gossipTextView"
    android:background="@android:drawable/editbox_background_normal"
    android:layout_gravity="start|top"/>

Any suggestions? 有什么建议么?

In order to remove the focus from the texView you have to add the following line of code in your AndroidMenifest.xml for that specific Activity in which the textView is included. 为了从texView中移出焦点,您必须在AndroidMenifest.xml针对包含textView的特定活动添加以下代码。

    <activity
        android:name=".yourActivity"
        android:label="Registration"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="stateHidden" >
    </activity>

In order to make single line scrollable text add 2 lines in your 为了使单行可滚动文本在您的计算机中添加2行

android:ellipsize="end"
android:singleLine="true"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM