在Android開發(fā)中,需要密碼的隱藏和顯示,下面就和大家分享一下使用方法:
創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比興國(guó)網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式興國(guó)網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋興國(guó)地區(qū)。費(fèi)用合理售后完善,10余年實(shí)體公司更值得信賴。
xml代碼:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/white"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="新密碼"
android:textColor="@color/black"
android:textSize="18dp"
android:gravity="center_vertical"
android:layout_marginLeft="15dp"/>
<EditText
android:id="@+id/newpassword"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:inputType="textPassword"
android:hint="請(qǐng)?jiān)O(shè)置登錄密碼"
android:background="@null"/>
<CheckBox
android:id="@+id/CheckBox"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="15dp"
android:textSize="16dp"
android:text="顯示"
/>
</LinearLayout>
隱藏圖標(biāo)代碼
android:button="@null"
JAVA代碼:
/**
* Created by fby on 2017/9/11.
*/
public class ChargepsdActivity extends Activity {
private EditText editText;
private CheckBox checkBox;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chargepsd);
editText = (EditText) findViewById(R.id.newpassword);
checkBox = (CheckBox) findViewById(R.id.CheckBox);
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
//如果選中,顯示密碼
editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
}else{
//否則隱藏密碼
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
}
});
}
}
效果展示:


以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。
新聞標(biāo)題:Android中實(shí)現(xiàn)密碼的隱藏和顯示的示例
文章地址:http://chinadenli.net/article10/phocdo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、外貿(mào)網(wǎng)站建設(shè)、云服務(wù)器、軟件開發(fā)、面包屑導(dǎo)航、網(wǎng)站策劃
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)