login介面 checkbox選擇顯示或者隱藏密碼
先來看看佈局檔案login.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.demotest.MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="賬號:" />
<EditText
android:id="@+id/edtlogin"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1000"
android:hint="輸入賬號" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密碼:" />
<EditText
android:id="@+id/edtpassword"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="輸入密碼" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="30dp" >
<CheckBox
android:id="@+id/checkbox"
android:layout_width="126dp"
android:layout_height="wrap_content"
android:text="顯示密碼" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/zhuchebtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="註冊" />
<Button
android:id="@+id/loginbtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="登入" />
</LinearLayout>
</LinearLayout>
就是很簡單的登入介面,我就不多解釋了。
下面我們來看mainActivity.class的程式碼
public class MainActivity extends Activity {
private Button loginbtn;
private EditText edtname;
private EditText edtpassword;
private String name;
private String password;
private CheckBox checkbox;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
loginbtn = (Button) findViewById(R.id.loginbtn);
edtname = (EditText) findViewById(R.id.edtlogin);
edtpassword = (EditText) findViewById(R.id.edtpassword);
checkbox = (CheckBox) findViewById(R.id.checkbox);
checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if (!isChecked) {
edtpassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
} else {
edtpassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
}
}
});
loginbtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
name = edtname.getText().toString();
password = edtpassword.getText().toString();
// TODO Auto-generated method stub
if (name.equals("jaytang") && password.equals("4011")) {
Intent intent = new Intent(MainActivity.this, Weixin.class);
startActivity(intent);
} else {
Toast.makeText(MainActivity.this, "false", Toast.LENGTH_SHORT).show();
}
}
});
}
}
主要看那個checkbox的監聽事件
checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if (!isChecked) {
edtpassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
} else {
edtpassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
}
}
});
相關文章
- 隱藏密碼?顯示密碼?密碼
- 點選按鈕顯示或者隱藏元素例項程式碼
- 動態隱藏/顯示選擇螢幕
- 點選開關顯示或者隱藏input文字框
- Android 眼睛 顯示隱藏密碼(ImageView)Android密碼View
- EditText設定密碼隱藏和顯示密碼
- js實現的點選顯示或者隱藏相關內容JS
- 搭建直播平臺,顯示隱藏密碼,眼睛特效密碼特效
- 直播平臺原始碼,input密碼框顯示與隱藏原始碼密碼
- win7工作列圖示設定(顯示或者隱藏)Win7
- 直播商城原始碼,密碼輸入框自定義顯示隱藏圖示原始碼密碼
- mac顯示隱藏檔案,取消顯示隱藏檔案Mac
- jsp頁面中點選(checkbox)或者radio隱藏trJS
- CSS點選隱藏和顯示div效果CSS
- 直播平臺原始碼,Android實現密碼顯示與隱藏原始碼Android密碼
- 直播系統程式碼,輸入時實現密碼顯示與隱藏密碼
- iOS 隱藏&顯示tabBariOStabBar
- jquery點選按鈕顯示和隱藏DIvjQuery
- MacOS X隱藏和顯示隱藏檔案Mac
- Mac顯示和隱藏“隱藏檔案”命令Mac
- H5 JS控制input表單密碼的顯示與隱藏H5JS密碼
- App之上下滑動UIScrollview隱藏或者顯示導航欄APPUIView
- jQuery實現的點選元素隱藏和顯示jQuery
- 點選按鈕動畫方式隱藏和顯示div動畫
- JavaScript點選切換div的顯示和隱藏JavaScript
- Android基礎 Android 顯示隱藏密碼的簡單實現Android密碼
- jQuery 效果 – 隱藏和顯示jQuery
- mac隱藏檔案顯示Mac
- view的隱藏和顯示View
- Mac 顯示隱藏檔案Mac
- Mac顯示/不顯示隱藏檔案教程!Mac
- 點選空白出隱藏鍵盤,或者點選按鈕隱藏軟鍵盤
- 點選按鈕實現隱藏和顯示的切換程式碼
- MAC如何顯示隱藏檔案和隱藏隱藏檔案的命令Mac
- Mac下顯示和隱藏隱藏檔案的命令Mac
- 點選同一按鈕顯示隱藏切換
- 點選按鈕實現div的顯示和隱藏
- JavaScript點選一個按鈕隱藏和顯示divJavaScript