欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android實現(xiàn)密碼明密文切換(小眼睛)

 更新時間:2022年08月02日 10:53:56   作者:JH學編程  
這篇文章主要為大家詳細介紹了Android實現(xiàn)密碼明密文切換,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Android實現(xiàn)密碼明密文切換的具體代碼,供大家參考,具體內(nèi)容如下

小眼睛在密碼欄右邊!

奉上我使用的素材:

添加圖片到res/darwable中

對安卓的知識掌握的非常淺,只知道 圖片名稱不要大寫,大寫會報錯!
如果格式正確仍會報錯的話,則 在gradle里加上這兩句,俺也不懂為什么,都沒有講原理的。

aaptOptions.cruncherEnabled = false
aaptOptions.useNewCruncher = false

編輯登錄頁.xml

文本+可編輯文本框+小眼睛圖片+按鈕
小眼睛只要寫一個ImageView即可

<LinearLayout
? ? ? ? ? ? android:id="@+id/ll_username"
? ? ? ? ? ? android:layout_below="@id/iv"
? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:layout_marginTop="60dp"
? ? ? ? ? ? android:layout_marginLeft="10dp"
? ? ? ? ? ? android:layout_marginRight="10dp"
? ? ? ? ? ? android:layout_marginBottom="5dp"
? ? ? ? ? ? android:layout_centerVertical="true"
? ? ? ? ? ? android:background="#6B009688">
? ? ? ? <TextView
? ? ? ? ? ? ? ? android:id="@+id/tv_login_username"
? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="賬號:"
? ? ? ? ? ? ? ? android:padding="10dp"
? ? ? ? ? ? ? ? android:textSize="20dp"
? ? ? ? ? ? ? ? android:textColor="@color/white"/>
? ? ? ? <EditText
? ? ? ? ? ? ? ? android:id="@+id/et_login_username"
? ? ? ? ? ? ? ? android:maxLines="1"
? ? ? ? ? ? ? ? android:maxLength="16"
? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:layout_marginLeft="10dp"
? ? ? ? ? ? ? ? android:background="@null"/>
? ? </LinearLayout>
? ? <LinearLayout
? ? ? ? ? ? android:id="@+id/ll_password"
? ? ? ? ? ? android:layout_below="@id/ll_username"
? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:layout_marginLeft="10dp"
? ? ? ? ? ? android:layout_marginRight="10dp"
? ? ? ? ? ? android:layout_centerVertical="true"
? ? ? ? ? ? android:background="#6B009688">
? ? ? ? <TextView
? ? ? ? ? ? ? ? android:id="@+id/tv_login_password"
? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="密碼:"
? ? ? ? ? ? ? ? android:padding="10dp"
? ? ? ? ? ? ? ? android:textSize="20dp"
? ? ? ? ? ? ? ? android:textColor="@color/white"/>
? ? ? ? <EditText
? ? ? ? ? ? ? ? android:id="@+id/et_login_password"
? ? ? ? ? ? ? ? android:maxLines="1"
? ? ? ? ? ? ? ? android:maxLength="6"
? ? ? ? ? ? ? ? android:layout_width="255dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:layout_marginLeft="10dp"
? ? ? ? ? ? ? ? android:background="@null"/>
? ? ? ? <ImageView android:layout_width="20dp"
? ? ? ? ? ? ? ? ? ?android:layout_height="20dp"
? ? ? ? ? ? ? ? ? ?android:layout_marginTop="14dp"
? ? ? ? ? ? ? ? ? ?android:id="@+id/display_password"/>
? ? </LinearLayout>
? ? <LinearLayout
? ? ? ? ? ? android:id="@+id/ll_btm"
? ? ? ? ? ? android:layout_below="@id/ll_password"
? ? ? ? ? ? android:gravity="center"
? ? ? ? ? ? android:orientation="vertical"
? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? android:layout_height="wrap_content">
? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/btn_login"
? ? ? ? ? ? ? ? android:layout_width="300dp"
? ? ? ? ? ? ? ? android:layout_height="50dp"
? ? ? ? ? ? ? ? android:layout_marginTop="50dp"
? ? ? ? ? ? ? ? android:text="登錄"
? ? ? ? ? ? ? ? android:textSize="18dp"
? ? ? ? ? ? ? ? android:background="@color/white"
? ? ? ? />
? ? </LinearLayout>

編輯登錄頁小眼睛功能.java

public class LoginActivity extends AppCompatActivity implements View.OnClickListener {

? ? private EditText loginUsername;
? ? private EditText loginPassword;
? ? private Button login;
? ? private ImageView displayPassword;
? ? private boolean isHideFirst = false;


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

? ? ? ? ActionBar actionBar = getSupportActionBar();
? ? ? ? if (actionBar != null) {
? ? ? ? ? ? actionBar.hide();
? ? ? ? }
? ? ? ? //隱藏標題欄

? ? ? ? login = findViewById(R.id.btn_login);
? ? ? ? loginUsername = findViewById(R.id.et_login_username);
? ? ? ? loginPassword = findViewById(R.id.et_login_password);
? ? ? ? displayPassword = findViewById(R.id.display_password);

? ? ? ? login.setOnClickListener(this);
? ? ? ? displayPassword.setOnClickListener(this);
? ? ? ? displayPassword.setImageResource(R.drawable.open);
? ? }

? ? @Override
? ? public void onClick(View v){
? ? ? ? switch (v.getId()) {
? ? ? ? ? ? case R.id.display_password:{
? ? ? ? ? ? ? ? if (isHideFirst) {
? ? ? ? ? ? ? ? ? ? displayPassword.setImageResource(R.drawable.open);
? ? ? ? ? ? ? ? ? ? HideReturnsTransformationMethod method1 = HideReturnsTransformationMethod.getInstance();
? ? ? ? ? ? ? ? ? ? loginPassword.setTransformationMethod(method1);
? ? ? ? ? ? ? ? ? ? isHideFirst = false;
? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? displayPassword.setImageResource(R.drawable.close);
? ? ? ? ? ? ? ? ? ? TransformationMethod method = PasswordTransformationMethod.getInstance();
? ? ? ? ? ? ? ? ? ? loginPassword.setTransformationMethod(method);
? ? ? ? ? ? ? ? ? ? isHideFirst = true;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? int index = loginPassword.getText().toString().length();
? ? ? ? ? ? ? ? loginPassword.setSelection(index);
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? case R.id.btn_login: {
?? ??? ??? ??? ?//。。。。。
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? }
? ? }
}

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • Android開發(fā)AsmClassVisitorFactory使用詳解

    Android開發(fā)AsmClassVisitorFactory使用詳解

    這篇文章主要為大家介紹了Android開發(fā)AsmClassVisitorFactory使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-06-06
  • Android第三方登錄之QQ登錄

    Android第三方登錄之QQ登錄

    這篇文章主要為大家詳細介紹了Android第三方登錄之QQ登錄,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • Android 保存文件路徑方法

    Android 保存文件路徑方法

    今天小編就為大家分享一篇Android 保存文件路徑方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08
  • Android不使用自定義布局情況下實現(xiàn)自定義通知欄圖標的方法

    Android不使用自定義布局情況下實現(xiàn)自定義通知欄圖標的方法

    這篇文章主要介紹了Android不使用自定義布局情況下實現(xiàn)自定義通知欄圖標的方法,實例分析了Android通知欄圖標的創(chuàng)建技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-12-12
  • Android實現(xiàn)TextView兩端對齊的方法

    Android實現(xiàn)TextView兩端對齊的方法

    這篇文章主要介紹了Android實現(xiàn)TextView兩端對齊的方法,需要的朋友可以參考下
    2016-01-01
  • 基于Android實現(xiàn)仿QQ5.0側滑

    基于Android實現(xiàn)仿QQ5.0側滑

    本課程將帶領大家通過自定義控件實現(xiàn)QQ5.0側滑菜單,課程將循序漸進,首先實現(xiàn)最普通的側滑菜單,然后引入屬性動畫與拖動菜單效果相結合,最終實現(xiàn)QQ5.0側滑菜單效果。通過本課程大家會對側滑菜單有更深層次的了解,通過自定義控件和屬性動畫打造千變?nèi)f化的側滑菜單效果
    2015-12-12
  • Android開發(fā)控制ScrollView滑動速度的方法

    Android開發(fā)控制ScrollView滑動速度的方法

    這篇文章主要介紹了Android開發(fā)控制ScrollView滑動速度的方法,結合實例形式分析了Android編程中ScrollView滑動事件相關操作技巧,需要的朋友可以參考下
    2017-02-02
  • 淺談Android應用安全防護和逆向分析之a(chǎn)pk反編譯

    淺談Android應用安全防護和逆向分析之a(chǎn)pk反編譯

    我們有時候在某個app上見到某個功能,某個效果蠻不錯的,我們想看看對方的思路怎么走的,這時候,我們就可以通過反編譯來編譯該apk,拿到代碼,進行分析。
    2021-06-06
  • 如何使用Mock修改Android設備上的features

    如何使用Mock修改Android設備上的features

    這篇文章主要介紹了如何使用Mock修改Android設備上的features,想了解Mock的同學可以參考下
    2021-04-04
  • Android仿美團分類下拉菜單實例代碼

    Android仿美團分類下拉菜單實例代碼

    這篇文章主要為大家詳細介紹了Android仿美團分類下拉菜單實例代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-05-05

最新評論