Android Auto Scrolling EditText Hint

懵懂的女人 提交于 2019-12-09 03:25:44

问题


problem with making edittext scrollable

there is mentioned that it is not scrollable with singleLine=true.

So i have 2 options:

  1. I check if the user inputs "\n" and delete that, then i have to worry about things in the second line, too.

  2. I use a custom textviews which scrolls through in a loop, could this be used here too only for the hint ?

     <com.test.ScrollingTextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_marginTop="1dp"
            android:layout_weight="0.17"
            android:background="@color/black"
            android:ellipsize="marquee"
            android:gravity="center_vertical"
            android:marqueeRepeatLimit="marquee_forever"
            android:paddingLeft="10dp"
            android:scrollHorizontally="true"
            android:singleLine="true"
            android:text="@string/editLength"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/white" />
    

public class ScrollingTextView extends TextView {

public ScrollingTextView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

public ScrollingTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public ScrollingTextView(Context context) {
    super(context);
}

@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
    if (focused)
        super.onFocusChanged(focused, direction, previouslyFocusedRect);
}

@Override
public void onWindowFocusChanged(boolean focused) {
    if (focused)
        super.onWindowFocusChanged(focused);
}

@Override
public boolean isFocused() {
    return true;
}

}

I just cant get this formated right. Sorry for that.


回答1:


Make your EditText Scrollable like this:

EditText yourEditText = new EditText(context);
yourEditText.setScroller(new Scroller(context)); 
yourEditText.setMaxLines(1); 
yourEditText.setVerticalScrollBarEnabled(true); 
yourEditText.setMovementMethod(new ScrollingMovementMethod());


来源:https://stackoverflow.com/questions/11373433/android-auto-scrolling-edittext-hint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!