ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

android登录界面

2020-11-30 16:04:14  阅读:179  来源: 互联网

标签:hobbys findViewById 界面 登录 show import android id


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:background="#F5F4F4"
android:orientation="vertical"
    tools:context="hhh.com.myapplication.MainActivity">

<TextView
    android:id="@+id/textView"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:background="#ffffff"
    android:enabled="true"
    android:gravity="center"
    android:text="注册界面"
    android:textColor="#292422"
    android:textSize="30sp" />

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:gravity="center">

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center">

        <TextView
            android:id="@+id/name"
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:enabled="true"
            android:text="用户名:"
            android:textSize="20sp"
            android:textStyle="bold" />

        <EditText
            android:id="@+id/etname"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textPersonName" />
    </TableRow>

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center">

        <TextView
            android:id="@+id/password"
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:enabled="true"
            android:text="密码:"
            android:textSize="20sp"
            android:textStyle="bold" />

        <EditText
            android:id="@+id/etpass"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="numberPassword" />

    </TableRow>
</TableLayout>

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="150dp"
    android:gravity="center">

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:enabled="true"
            android:text="性别:"
            android:textSize="20sp"
            android:textStyle="bold" />

        <RadioGroup
            android:id="@+id/rg"
            android:layout_width="220dp"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <RadioButton
                android:id="@+id/girl"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="女" />

            <RadioButton
                android:id="@+id/boy"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="男" />
        </RadioGroup>
    </TableRow>

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:gravity="center">

        <TextView
            android:id="@+id/textView7"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:enabled="true"
            android:text="爱好:"
            android:textSize="20sp"
            android:textStyle="bold" />

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

            <CheckBox
                android:id="@+id/print"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="电影" />

            <CheckBox
                android:id="@+id/basketball"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="书法" />
        </LinearLayout>

    </TableRow>

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center">

        <TextView
            android:id="@+id/textView8"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="20sp" />

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

            <CheckBox
                android:id="@+id/sing"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="唱歌" />

            <CheckBox
                android:id="@+id/dance"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="看书" />
        </LinearLayout>
    </TableRow>
</TableLayout>

<Button
    android:id="@+id/button"
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:background="#ffff"
    android:text="注册"
    android:textAllCaps="false"
    android:textColor="#252523"
    android:textStyle="bold" />

</LinearLayout>
<?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">

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="#ffff"
        android:gravity="center"
        android:text="注册信息"
        android:textColor="#151616"
        android:textSize="25sp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="25dp"
        android:gravity="center"
        android:orientation="vertical">

        <TextView
            android:id="@+id/textView3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="你的注册信息是:"
            android:textSize="20sp" />

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="400dp">

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/textView4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="用户名:"
                    android:textSize="20sp" />

                <TextView
                    android:id="@+id/show_name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />
            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/textView9"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="密码:"
                    android:textSize="20sp" />

                <TextView
                    android:id="@+id/show_pass"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />
            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/textView11"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="性别:"
                    android:textSize="20sp" />

                <TextView
                    android:id="@+id/show_gender"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />
            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/textView13"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="爱好:"
                    android:textSize="20sp" />

                <TextView
                    android:id="@+id/show_hobby"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />
            </TableRow>
        </TableLayout>
    </LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapplication">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name="hhh.com.myapplication.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="hhh.com.myapplication.secondActivity"/>
    </application>

</manifest>
package hhh.com.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.example.myapplication.R;


public class MainActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {

    private String hobbys;
    final Intent intent = new Intent();
    private EditText name;
    private EditText password;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        name = (EditText)findViewById(R.id.etname);
        password = (EditText)findViewById(R.id.etpass);
        RadioGroup  rg = (RadioGroup)findViewById(R.id.rg);
        CheckBox print = (CheckBox)findViewById(R.id.print);
        CheckBox basketball = (CheckBox)findViewById(R.id.basketball);
        CheckBox sing = (CheckBox)findViewById(R.id.sing);
        CheckBox dance = (CheckBox)findViewById(R.id.dance);
        hobbys = new String();

        //设置跳转到的Activity
        intent.setClass(MainActivity.this,secondActivity.class);



        //为RadioGroup设置监听
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == R.id.girl){
                    intent.putExtra("gender", "女");
                }else if (i == R.id.boy){
                    intent.putExtra("gender", "男");
                }
            }
        });

        //为CheckBox设置监听
        print.setOnCheckedChangeListener(this);
        basketball.setOnCheckedChangeListener(this);
        sing.setOnCheckedChangeListener(this);
        dance.setOnCheckedChangeListener(this);


        //为 Button设置监听
        Button button = (Button)findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle = new Bundle();
                bundle.putString("name",name.getText().toString());
                bundle.putString("password",password.getText().toString());
                intent.putExtras(bundle);
                startActivity(intent);

            }
        });
    }

    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        String motion = compoundButton.getText().toString();
        if (b){
            if(!hobbys.contains(motion)){
                hobbys = hobbys + motion;
                intent.putExtra("hobbys", hobbys);
            }
        }else{
            if (hobbys.contains(motion)){
                hobbys = hobbys.replace(motion,"");
                intent.putExtra("hobbys", hobbys);
            }
        }
    }
}
package hhh.com.myapplication;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;

import com.example.myapplication.R;


public class secondActivity extends Activity {

    public void startActivity(Intent intent){

    }
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.news);
        TextView show_name = (TextView)findViewById(R.id.show_name);
        TextView show_pass =(TextView)findViewById(R.id.show_pass);
        TextView show_gender = (TextView)findViewById(R.id.show_gender);
        TextView show_hobby =(TextView)findViewById(R.id.show_hobby);
        Intent intent = getIntent();
        Bundle bundle = getIntent().getExtras();
        show_name.setText(bundle.getString("name"));
        show_pass.setText(bundle.getString("password"));
        show_gender.setText(intent.getStringExtra("gender"));
        show_hobby.setText(intent.getStringExtra("hobbys"));

    }

    public void finish(){

    }
}

标签:hobbys,findViewById,界面,登录,show,import,android,id
来源: https://www.cnblogs.com/dayttt/p/14061781.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有