每日总结2023/2/23
今天继续进行安卓的学习
用户名文本框
<?xml version="1.0" encoding="utf-8"?> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> <EditText android:hint="请输入用户名" android:textColorHint="@color/colorAccent" android:layout_width="200dp" android:layout_height="200dp" /> </LinearLayout>
获取输入的内容
xml文件代码
<?xml version="1.0" encoding="utf-8"?> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> <EditText android:id="@+id/et" android:hint="请输入用户名" android:textColorHint="@color/colorAccent" android:inputType="phone" android:drawableLeft="@drawable/login" android:drawablePadding="10dp" android:paddingLeft="10dp" android:layout_width="200dp" android:layout_height="100dp" /> <EditText android:hint="请输入密码" android:textColorHint="@color/colorAccent" android:inputType="textPassword" android:drawableLeft="@drawable/login" android:drawablePadding="10dp" android:paddingLeft="10dp" android:layout_width="200dp" android:layout_height="100dp" /> <Button android:id="@+id/btn" android:text="登录" android:layout_width="52dp" android:layout_height="52dp" /> </LinearLayout>
java文件代码
package com.example.a86191.myedittext; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; private EditText et; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn=findViewById(R.id.btn); et= findViewById(R.id.et); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String text = et.getText().toString(); Log.e(TAG, "输入的内容" +text); } }); } }
package com.example.a86191.myedittext; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ProgressBar; public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; private EditText et; private ProgressBar Progressbar; @Override protected void onCreate(Bundle savedInstanceState) { Progressbar =findViewById(R.id.bp); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn=findViewById(R.id.btn); et= findViewById(R.id.et); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String text = et.getText().toString(); Log.e(TAG, "输入的内容" +text); } }); } public void zw(View view) { if (Progressbar.getVisibility()==View.GONE){ Progressbar.setVisibility(View.VISIBLE); }else{ Progressbar.setVisibility(View.GONE); } } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> <EditText android:id="@+id/et" android:hint="请输入用户名" android:textColorHint="@color/colorAccent" android:inputType="phone" android:drawableLeft="@drawable/login" android:drawablePadding="10dp" android:paddingLeft="10dp" android:layout_width="200dp" android:layout_height="100dp" /> <EditText android:hint="请输入密码" android:textColorHint="@color/colorAccent" android:inputType="textPassword" android:drawableLeft="@drawable/login" android:drawablePadding="10dp" android:paddingLeft="10dp" android:layout_width="200dp" android:layout_height="100dp" /> <Button android:id="@+id/btn" android:text="登录" android:layout_width="52dp" android:layout_height="52dp" /> <ImageView android:layout_width="150dp" android:layout_height="100dp" android:scaleType="fitStart" android:src="@drawable/erzi" /> <ProgressBar android:id="@+id/bp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:onClick="zw" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="显示隐藏" /> </LinearLayout>