标签:androidx Studio choose 跳转 import Android btn android result
注册界面:
代码:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".RegActivity"
android:padding="20dp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:orientation="horizontal">
<TextView
android:id="@+id/tvuser"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="用户名" />
<EditText
android:id="@+id/user"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:ems="10"
android:hint="请输入用户名"
android:inputType="textPersonName"
android:minHeight="48dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:text="使用头像" />
<ImageView
android:id="@+id/reg_img"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_weight="3"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_choose"
android:text="选择头像">
</Button>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:orientation="horizontal">
<TextView
android:id="@+id/tvpwo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="密码" />
<EditText
android:id="@+id/pwo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:ems="10"
android:hint="请输入密码"
android:inputType="textPassword"
android:minHeight="48dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:orientation="horizontal">
<TextView
android:id="@+id/tvrepwo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="确认密码" />
<EditText
android:id="@+id/rpw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="请确认密码"
android:inputType="textPassword"
android:minHeight="48dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:orientation="horizontal">
<TextView
android:id="@+id/tvname"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="姓名" />
<EditText
android:id="@+id/uname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="请输入您的姓名"
android:inputType="textPersonName"
android:minHeight="48dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal">
<TextView
android:id="@+id/sex"
android:layout_width="145dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="性别"
tools:text="性别" />
<RadioGroup
android:id="@+id/sexq"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<RadioButton
android:id="@+id/ButtonM"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="男"
tools:ignore="TouchTargetSizeCheck" />
<RadioButton
android:id="@+id/ButtonW"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="女"
tools:ignore="TouchTargetSizeCheck" />
</RadioGroup>
</LinearLayout>
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="已阅读会员协议" />
<Button
android:id="@+id/buttonR"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="注册" />
<Button
android:id="@+id/buttonB"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="返回" />
<TextView
android:id="@+id/tvRC"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
功能代码RegActivity.java
package com.example.gridviewtest;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class RegActivity extends AppCompatActivity {
ImageView iv;
Button btn_choose;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
iv=(ImageView) findViewById(R.id.reg_img);
btn_choose=(Button)findViewById(R.id.btn_choose);
btn_choose.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
mGetContent.launch("image/*");
}
});
}
ActivityResultLauncher<String> mGetContent = registerForActivityResult(new ActivityResultContracts.GetContent(),
new ActivityResultCallback<Uri>() {
@Override
public void onActivityResult(Uri uri) {
// Handle the returned Uri
}
});
}
标签:androidx,Studio,choose,跳转,import,Android,btn,android,result 来源: https://www.cnblogs.com/ILEQ/p/16129442.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。