您的位置:首页 > 其它

EditText 不可编辑状态的实现

2014-01-15 16:08 381 查看
add_assert_Code.setClickable(false);

add_assert_Code.setEnabled(false);

2行代码实现 !

<LinearLayout
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@drawable/fr_bg_notop"
android:padding="8dip"
android:focusable="true"
android:focusableInTouchMode="true"
>

<TextView
android:textSize="@dimen/medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="设备名称:"
android:textColor="@color/black"
/>

<EditText
android:id="@+id/add_assert_Name"
android:textSize="@dimen/medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/tv_bg"
android:paddingLeft="10dip"
android:singleLine="true"
android:textColor="@color/black"
android:gravity="center"
/>

</LinearLayout>


通过看 editText 源代码 要方便实现 转换 可以 自定义的editText

但是重写editText 需要 改xml 有点麻烦 ,

可以不可以 通过代码直接实现?

要实现动态 ,就不可以修改 xml 。xml 还是原来正常方式。

思考思路 是 先使 EditText 不获取到焦点 , 看到里面有一个方法 setClickable(false); 不可以点击 。 写上之后 ,不管用,还是可以编辑的。

然后 就想 在view 生成之后 ,信息都显示出来了, 现在就废掉 editText就可以了

setEnabled(false); 看字面 意思 ,enabled 失效 的意思 。代码写上 完全实现 我们的要的功能。

在父布局中

android:focusable="true"
android:focusableInTouchMode="true"
设计的作用 是 使View生成的时候 EditText 开始的时候不会得到焦点 。 因为一得到焦点 ,会弹出输入 界面,提高用户体验 。

功能的实现不重要,重要的是实现功能的 思考思路。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: