国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android中實現密碼的隱藏和顯示的示例

2019-10-22 18:27:51
字體:
來源:轉載
供稿:網友

在Android開發中,需要密碼的隱藏和顯示,下面就和大家分享一下使用方法:

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="請設置登錄密碼"        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>

隱藏圖標代碼

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());        }      }    });  }}

效果展示:

android,密碼顯示隱藏,密碼隱藏和顯示

android,密碼顯示隱藏,密碼隱藏和顯示

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 静海县| 纳雍县| 永吉县| 吉木乃县| 香港 | 大新县| 玉溪市| 辛集市| 老河口市| 惠州市| 龙里县| 临武县| 怀安县| 清流县| 房产| 搜索| 张家港市| 子长县| 新闻| 射阳县| 明光市| 富锦市| 淅川县| 余姚市| 玉龙| 富平县| 乐亭县| 澳门| 瑞昌市| 庆安县| 监利县| 海盐县| 谢通门县| 新巴尔虎右旗| 二手房| 六枝特区| 淅川县| 武强县| 庄浪县| 清丰县| 屏东市|