禁用可编辑的EditText和重点(如TextView中) [英] Disable EditText editability and focus (like TextView)
问题描述
有没有一种方法,使Android中的EditText
的行为,如的TextView
(XML是prefered)?
我已经试过如下:
Is there a way to make EditText
behaviors like TextView
in Android (XML is prefered)?
I have tried the following:
android:editable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:cursorVisible="false"
android:longClickable="false"
这工作,但我还是能触摸到的EditText
来获得焦点(橙色边境),但关注的焦点,只要我取出我的手指失去了。
我不知道是什么 focusableInTouchMode
没有,但它不会删除焦点时,我保持感人。
This works but I still can touch the EditText
to get focus (the orange boarder), though the focus lost as soon as I remove my finger.
I'm not sure what focusableInTouchMode
does, but it doesn't remove the focus when I keep touching.
和我为什么不使用白色背景的TextView
的原因,而不是在于的TextView
的背景是丑陋的。 的EditText
的背景有圆角和阴影效果。
And the reason why I don't use a white background TextView
instead is that the TextView
's background is ugly. EditText
's background has round corners and shadow effect.
在此先感谢。
推荐答案
的EditText
和的TextView
很相似。唯一的区别我看到硬coded进入<一href="http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/widget/EditText.java">EditText.java是设置可编辑默认为true,这你手动设置。除此之外,在的EditText
<一个href="http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/res/res/values/styles.xml">style是:
EditText
and TextView
are quite similar. The only difference I see hard-coded into EditText.java is to set the editable default to true, which you've set manually. Other than that, the EditText
style is:
<style name="Widget.EditText">
<item name="android:focusable">true</item>
<item name="android:focusableInTouchMode">true</item>
<item name="android:clickable">true</item>
<item name="android:background">@android:drawable/edit_text</item>
<item name="android:textAppearance">?android:attr/textAppearanceMediumInverse</item>
<item name="android:textColor">@android:color/primary_text_light</item>
<item name="android:gravity">center_vertical</item>
</style>
和的TextView
是:
<style name="Widget.TextView">
<item name="android:textAppearance">?android:attr/textAppearanceSmall</item>
</style>
我的猜测是, @android:绘制/ edit_text
是橙色框的源代码。事实上,<一个href="http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/res/res/drawable/edit_text.xml">it包含:
My guess is that @android:drawable/edit_text
is the source of the orange box. Indeed, it contains:
<item android:state_pressed="true" android:drawable="@drawable/textfield_pressed"/>
最简单的方法可能是它的背景设置为默认之一:
The simplest way might be to set its background to the default one:
安卓背景=@机器人:可绘制/ textfield_default
这篇关于禁用可编辑的EditText和重点(如TextView中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!