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

首頁 > 系統(tǒng) > Android > 正文

Android中實現(xiàn)密碼的隱藏和顯示的示例

2019-12-12 02:02:30
字體:
來源:轉載
供稿:網友

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

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

效果展示:


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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 东乡县| 迁安市| 诏安县| 阿克苏市| 阳高县| 绥江县| 星座| 德钦县| 屏南县| 濮阳县| 新竹市| 连城县| 休宁县| 灵丘县| 天峨县| 泸西县| 丰都县| 宜春市| 巴彦县| 澄江县| 福建省| 丘北县| 育儿| 周宁县| 理塘县| 华池县| 金坛市| 阳谷县| 蒲城县| 克山县| 太谷县| 阳泉市| 垫江县| 都昌县| 贵阳市| 江阴市| 林口县| 合江县| 渑池县| 长宁区| 辰溪县|