最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android自定義密碼樣式 黑點(diǎn)轉(zhuǎn)換成特殊字符

 更新時(shí)間:2017年07月10日 15:57:13   作者:u014620028  
這篇文章主要為大家詳細(xì)介紹了Android自定義密碼樣式的制作方法,黑點(diǎn)換成¥、%等特殊字符,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文為大家分享了Android自定義密碼樣式的制作代碼,黑點(diǎn)換成¥、%等特殊字符,供大家參考,具體內(nèi)容如下

復(fù)制下面代碼即可:

布局:

<?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:orientation="vertical"
  >

  <EditText
    android:id="@+id/et"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_marginTop="25dp"
    android:hint="請(qǐng)輸入數(shù)據(jù)"
    />

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:orientation="horizontal">

    <Button
      android:id="@+id/password"
      android:layout_width="0dp"
      android:layout_height="match_parent"
      android:layout_weight="1"
      android:text="密文"/>

    <Button
      android:id="@+id/show_text"
      android:layout_width="0dp"
      android:layout_height="match_parent"
      android:layout_marginLeft="20dp"
      android:layout_weight="1"
      android:text="明文"/>
  </LinearLayout>

  <Button
    android:id="@+id/clean"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:text="清除"/>
</LinearLayout>

activity:

package com.chen;


import android.app.Activity;
import android.os.Bundle;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {

  Button psd;
  Button show_text;
  EditText et;
  Button clean;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //將輸入框中的內(nèi)容變?yōu)槊艽a格式
    psd = (Button) findViewById(R.id.password);
    //將密碼變?yōu)槊魑?
    show_text = (Button) findViewById(R.id.show_text);
    //清空輸入框
    clean = (Button) findViewById(R.id.clean);
    et = (EditText) findViewById(R.id.et);
    show_text.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        //獲取編輯框中的數(shù)據(jù)內(nèi)容
        String context = et.getText().toString();
        //將密碼變?yōu)槊魑?,這里不用setInputType
        et.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
        //設(shè)置光標(biāo)位置在數(shù)據(jù)最后
        et.setSelection(context.length());
      }
    });
    psd.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        //獲取編輯框中的數(shù)據(jù)內(nèi)容
        String context = et.getText().toString();
        //將數(shù)據(jù)變?yōu)橹付邮降拿艽a
        et.setTransformationMethod(new AsteriskPasswordTransformationMethod());
        //設(shè)置光標(biāo)位置在數(shù)據(jù)最后
        et.setSelection(context.length());
      }
    });
    clean.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        et.setText("");
      }
    });

  }

  private class AsteriskPasswordTransformationMethod extends PasswordTransformationMethod {
    @Override
    public CharSequence getTransformation(CharSequence source, View view) {
      return new PasswordCharSequence(source);
    }

    private class PasswordCharSequence implements CharSequence {
      private CharSequence mSource;

      public PasswordCharSequence(CharSequence source) {
        mSource = source; // Store char sequence
      }

      public char charAt(int index) {
        /*
        當(dāng)在編輯框中輸入1的時(shí)候,會(huì)連續(xù)打印0...
        當(dāng)在編輯框中繼續(xù)輸入2的時(shí)候,會(huì)連續(xù)01...
        不影響功能使用,但是出現(xiàn)原因不知,待解決
         */
        System.out.println("-----" + index + "-----");
        //這里返回的char,就是密碼的樣式,注意,是char類(lèi)型的
        return '$'; // This is the important part
      }

      public int length() {
        return mSource.length(); // Return default
      }

      public CharSequence subSequence(int start, int end) {
        return mSource.subSequence(start, end); // Return default
      }
    }
  }

}


以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android應(yīng)用中使用TabHost組件繼承TabActivity的布局方法

    Android應(yīng)用中使用TabHost組件繼承TabActivity的布局方法

    這篇文章主要介紹了Android應(yīng)用中使用TabHost組件繼承TabActivity的布局方法,文中分別介紹了以Activity和以布局文件進(jìn)行布局的方式,需要的朋友可以參考下
    2016-04-04
  • Android啟動(dòng)頁(yè)出現(xiàn)白屏、黑屏的解決方案

    Android啟動(dòng)頁(yè)出現(xiàn)白屏、黑屏的解決方案

    這篇文章主要給大家介紹了關(guān)于Android啟動(dòng)頁(yè)出現(xiàn)白屏、黑屏的解決方案,這一個(gè)需求是每位Android開(kāi)發(fā)者都需要的,最近發(fā)現(xiàn)了一個(gè)不錯(cuò)的解決方法,所以分享給大家,文中給出了詳細(xì)的介紹,需要的朋友可以參考下。
    2017-12-12
  • 基于Retrofit2+RxJava2實(shí)現(xiàn)Android App自動(dòng)更新

    基于Retrofit2+RxJava2實(shí)現(xiàn)Android App自動(dòng)更新

    這篇文章主要為大家詳細(xì)介紹了基于Retrofit2+RxJava2實(shí)現(xiàn)Android App自動(dòng)更新,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • android創(chuàng)建和刪除文件夾和文件的實(shí)現(xiàn)方法

    android創(chuàng)建和刪除文件夾和文件的實(shí)現(xiàn)方法

    下面小編就為大家?guī)?lái)一篇android創(chuàng)建和刪除文件夾和文件的實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-03-03
  • Android應(yīng)用隱私合規(guī)檢測(cè)實(shí)現(xiàn)方案詳解

    Android應(yīng)用隱私合規(guī)檢測(cè)實(shí)現(xiàn)方案詳解

    這篇文章主要介紹了Android應(yīng)用隱私合規(guī)檢測(cè)實(shí)現(xiàn)方案,我們需要做的就是提前檢測(cè)好自己的應(yīng)用是否存在隱私合規(guī)問(wèn)題,及時(shí)整改過(guò)來(lái),下面提供Xposed Hook思路去檢測(cè)隱私合規(guī)問(wèn)題,建議有Xposed基礎(chǔ)的童鞋閱讀,需要的朋友可以參考下
    2022-07-07
  • android popuwindow點(diǎn)擊外部窗口不消失的實(shí)例

    android popuwindow點(diǎn)擊外部窗口不消失的實(shí)例

    下面小編就為大家?guī)?lái)一篇android popuwindow點(diǎn)擊外部窗口不消失的實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-04-04
  • Gradle學(xué)習(xí)教程之部署上傳項(xiàng)目詳解

    Gradle學(xué)習(xí)教程之部署上傳項(xiàng)目詳解

    這篇文章主要給大家介紹了關(guān)于Gradle學(xué)習(xí)教程之部署上傳項(xiàng)目的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-04-04
  • android studio xml文件實(shí)現(xiàn)添加注釋

    android studio xml文件實(shí)現(xiàn)添加注釋

    這篇文章主要介紹了android studio xml文件實(shí)現(xiàn)添加注釋?zhuān)哂泻芎玫膮⒖純r(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-03-03
  • Android 內(nèi)存泄漏的幾種可能總結(jié)

    Android 內(nèi)存泄漏的幾種可能總結(jié)

    本文主要介紹 Android 內(nèi)存泄漏的幾種可能進(jìn)行總結(jié),這里整理了八種可以性,并一一介紹,有需要的小伙伴可以參考下
    2016-09-09
  • Android原生繪圖工具Paint詳細(xì)

    Android原生繪圖工具Paint詳細(xì)

    這篇文章要給大家分享的是Android原生繪圖工具Paint,android中提供了類(lèi)似的工具Canvas和Paint,分別對(duì)應(yīng)畫(huà)布和畫(huà)筆,本文就來(lái)介紹Androi中的Paint,感興趣的小伙伴一起來(lái)學(xué)習(xí)下面文章內(nèi)容
    2021-09-09

最新評(píng)論

临城县| 图们市| 淅川县| 林西县| 从江县| 宝鸡市| 无为县| 象山县| 邳州市| 肇源县| 镇江市| 陈巴尔虎旗| 禹州市| 三明市| 静安区| 天祝| 府谷县| 合江县| 许昌县| 依兰县| 房产| 贞丰县| 上栗县| 和顺县| 库车县| 萨迦县| 临沂市| 介休市| 旺苍县| 邳州市| 西昌市| 稷山县| 汕尾市| 华安县| 比如县| 章丘市| 延川县| 沁源县| 清远市| 绥德县| 安泽县|