【问题标题】:Disable Scrolling effect in EditText and still have visible cursor在 EditText 中禁用滚动效果并且仍然有可见的光标
【发布时间】:2017-09-09 07:59:38
【问题描述】:

我想在 EditText 对象中禁用滚动。我关注了this,但它导致光标在 EditText 内消失,这是不希望的。我想禁用滚动效果,但仍希望光标在 EditText 内。这是 EditText 对象的 XML。

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:layout_gravity="top|center"
    android:background="@color/grayBackground"
    android:orientation="horizontal"
    android:padding="8dp"
    android:layout_margin="10dp">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_view_carousel_grey_24dp"
        android:layout_gravity="center_vertical"
        android:paddingStart="2dp"
        android:paddingEnd="8dp"/>

    <EditText
        android:id="@+id/search_product"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:background="@android:color/transparent"
        android:hint="@string/searchProducts"/>

</LinearLayout>

【问题讨论】:

    标签: java android jquery xml android-studio


    【解决方案1】:

    如果您想禁用编辑文本框的滚动,请为 layout_height 设置静态高度

    <EditText
    
    <!--set static height instead of giving wrap content-->
            android:layout_height="wrap_content"
            />
    

    【讨论】:

    • 是的,它帮助实现了我想要的。谢谢:)
    【解决方案2】:

    Edittext标签下添加xml:

    android:cursorVisible="true" 
    

    或者,

    edittext.setCursorVisible(true).
    

    【讨论】:

    • 这样做很有帮助,即使输入一个字符,光标也会消失。
    • 感谢您的帮助! :)
    • @AbhayManiyar 如果答案有效..您应该通过单击答案旁边的勾号将其标记为正确...谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-22
    • 1970-01-01
    • 2017-10-31
    • 2020-07-27
    • 2010-11-13
    • 1970-01-01
    • 2015-08-03
    相关资源
    最近更新 更多