我想在 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>
最佳答案
如果你想禁用编辑文本框的滚动设置 layout_height 的静态高度
<EditText
<!--set static height instead of giving wrap content-->
android:layout_height="wrap_content"
/>
关于java - 在 EditText 中禁用滚动效果并且仍然有可见的光标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43388151/