让edittext不自动获取焦点入坑与出坑记
2016-07-13 15:37
316 查看
先看代码再看套路
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_color"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<include layout="@layout/activity_top_back_title_more" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<!-- -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:orientation="vertical" >
<EditText
android:id="@+id/et_number"
style="@style/BlueStrokeEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="사용자명을 입력하십시오"
android:singleLine="true" />
<EditText
android:id="@+id/et_password"
style="@style/BlueStrokeEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:hint="@string/input_password"
android:inputType="textWebPassword"
android:singleLine="true"
android:textSize="16sp" />
<TextView
android:id="@+id/btn_login"
style="@style/BlueButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:clickable="true"
android:gravity="center"
android:text="@string/login" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="40dp"
android:orientation="horizontal" >
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="#DDDCDB" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:gravity="center"
android:text="@string/wxlogin"
android:textColor="#DDDCDB" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="#DDDCDB" />
</LinearLayout>
<ImageView
android:id="@+id/loginbywx"
style="@style/BlueButton"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:background="@drawable/loginbywechat"
android:clickable="true"
android:contentDescription="@string/wxlogin"
android:scaleType="centerInside" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="@string/fastlogin"
android:textColor="#DDDCDD" />
</LinearLayout>
</ScrollView>
</LinearLayout>java代码部分
et_number.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO 清除hint
if (hasFocus) {
et_number.setHint("");
} else {
et_number.setHint("사용자명을 입력하십시오");
}
}
});
et_password.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
et_password.setHint("");
} else {
et_password.setHint(getString(R.string.input_password));
}
}
});
网友们都说 ,在edittext的父布局去加上
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_color"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<include layout="@layout/activity_top_back_title_more" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<!-- -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:orientation="vertical" >
<EditText
android:id="@+id/et_number"
style="@style/BlueStrokeEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="사용자명을 입력하십시오"
android:singleLine="true" />
<EditText
android:id="@+id/et_password"
style="@style/BlueStrokeEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:hint="@string/input_password"
android:inputType="textWebPassword"
android:singleLine="true"
android:textSize="16sp" />
<TextView
android:id="@+id/btn_login"
style="@style/BlueButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:clickable="true"
android:gravity="center"
android:text="@string/login" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="40dp"
android:orientation="horizontal" >
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="#DDDCDB" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:gravity="center"
android:text="@string/wxlogin"
android:textColor="#DDDCDB" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="#DDDCDB" />
</LinearLayout>
<ImageView
android:id="@+id/loginbywx"
style="@style/BlueButton"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:background="@drawable/loginbywechat"
android:clickable="true"
android:contentDescription="@string/wxlogin"
android:scaleType="centerInside" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="@string/fastlogin"
android:textColor="#DDDCDD" />
</LinearLayout>
</ScrollView>
</LinearLayout>java代码部分
et_number.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO 清除hint
if (hasFocus) {
et_number.setHint("");
} else {
et_number.setHint("사용자명을 입력하십시오");
}
}
});
et_password.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
et_password.setHint("");
} else {
et_password.setHint(getString(R.string.input_password));
}
}
});
网友们都说 ,在edittext的父布局去加上
android:focusable="true" android:focusableInTouchMode="true"就好了,我加上之后没卵用,之后又各种改,都没达到要求,最终试了一下 ,放到最外层布局,嗯 就是这样 。不多说,我是红领巾
相关文章推荐
- 在同一个页面中加载不同的子视图时,传值不需要再初始化字控制器,直接获取当前需要的子视图
- Graphviz 入门
- (4.6.17.1)进程保活(一、Android层面):关于 Android 进程保活,你所需要知道的一切
- java--关于线程同步(5种同步方式)
- WinForms UI控件初探:Grid Control 、Data Grid、TreeList
- 编程思想之多线程与多进程(1)——以操作系统的角度述说线程与进程
- TMS320F28335学习笔记------中断
- expect安装和测试
- <s:set>标签中value使用表达式变量的问题
- spring声明式事务管理的几种方式
- Eclipse 启动tomcat 访问主页报错404
- Bzoj3782:上学路线:组合数学+Lucas+CRT+DP
- WeX5不同步刷新导致的天坑
- 关于调用sort排序
- 谈谈对Spring IOC的理解
- ATOM基础教程一linter-php配置(12)
- framework(Error)
- centos7设置网关
- hdu4333 Revolving Digits - exkmp
- mvn常用命令