尝试学习吾爱的Android逆向!从零开始!在此记录进程!
弄了一个乱乱的UI界面
<?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:layout_margin="20dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:text="姓名:"/>
<EditText
android:id="@+id/ed_name"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:hint="请输入你的姓名!"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:text="年龄:"/>
<EditText
android:id="@+id/ed_age"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:hint="请输入你的年龄!"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:text="请选择你出生日期:"/>
<TextView
android:id="@+id/tv_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<Button
android:id="@+id/bt_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:text="选择日期"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:text="请输入你的邮箱:"/>
<EditText
android:id="@+id/ed_email"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:hint="请输入你的邮箱!"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请选择你的兴趣爱好:"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<CheckBox
android:id="@+id/cb_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Android"/>
<CheckBox
android:id="@+id/cb_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="IOS"/>
<CheckBox
android:id="@+id/cb_c"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="吹水"/>
</LinearLayout>
</LinearLayout>
<Button
android:id="@+id/bt_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="提交"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:text="用户名:"/>
<EditText
android:id="@+id/ed_username"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:text="密 码:"/>
<EditText
android:id="@+id/ed_password"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
</LinearLayout>
<Button
android:id="@+id/bt_go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:text="登录"
/>
</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:layout_margin="20dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="姓名:"/>
<TextView
android:id="@+id/tv_cname"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="年龄:"/>
<TextView
android:id="@+id/ctv_cage"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="邮箱:"/>
<TextView
android:id="@+id/tv_cemail"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="生日:"/>
<TextView
android:id="@+id/tv_ctime"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="爱好:"/>
<TextView
android:id="@+id/tv_ccb"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
布局就2个 搞定之后 就开始我们的逆向之旅了
首先在MainActivity中声明控件,以及传值,监听事件! 当然登录功能没做跳转,只是弹幕提醒登录成功失败与否而已!
package com.example.administrator.pj_001;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity implements View.OnClickListener{
//声明各个控件
private TextView tv_date;
private Button bt_time;
private Button bt_login;
private Button bt_go;
private EditText ed_name;
private EditText ed_age;
private EditText ed_email;
private EditText ed_username;
private EditText ed_password;
private CheckBox cb_a;
private CheckBox cb_b;
private CheckBox cb_c;
//存放ChecBox多选的内容
StringBuffer sb = new StringBuffer();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//初始化控件
initView();
//为按钮添加监听事件
bt_time.setOnClickListener(this);
bt_login.setOnClickListener(this);
bt_go.setOnClickListener(this);
}
//初始化控件
private void initView() {
tv_date = findViewById(R.id.tv_date);
bt_time = findViewById(R.id.bt_time);
bt_login = findViewById(R.id.bt_login);
bt_go = findViewById(R.id.bt_go);
ed_name = findViewById(R.id.ed_name);
ed_age = findViewById(R.id.ed_age);
ed_email = findViewById(R.id.ed_email);
cb_a = findViewById(R.id.cb_a);
cb_b = findViewById(R.id.cb_b);
cb_c = findViewById(R.id.cb_c);
ed_username = findViewById(R.id.ed_username);
ed_password = findViewById(R.id.ed_password);
}
@Override
public void onClick(View v) {
switch(v.getId()){
//点击选择日期的时候,使用DataPickerDialog弹框选择
case R.id.bt_time:
new DatePickerDialog(MainActivity.this,new DatePickerDialog.OnDateSetListener(){
@SuppressLint("DefaultLocale")
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
tv_date.setText(String.format("%d-%d-%d",year,month+1,dayOfMonth));
Toast.makeText(MainActivity.this,tv_date.getText().toString(),Toast.LENGTH_SHORT).show();
}
},2018,6,21).show();
break;
case R.id.bt_login:
//跳转到另外一个Activity,并把页面参数带过去!
Intent intent = new Intent(MainActivity.this,Client.class);
//实例化一个Bundle
Bundle bundle = new Bundle();
//存入数据
bundle.putString("name",ed_name.getText().toString());
bundle.putString("age",ed_age.getText().toString());
bundle.putString("time",tv_date.getText().toString());
bundle.putString("email",ed_email.getText().toString());
//判断是否选中,选中的状态下把多选框的值存入StringBuffer
if(cb_a.isChecked()){
sb.append(cb_a.getText().toString()+" ");
}
if(cb_b.isChecked()){
sb.append(cb_b.getText().toString()+" ");
}
if(cb_c.isChecked()) {
sb.append(cb_c.getText().toString() + " ");
}
Toast.makeText(MainActivity.this,sb.toString(),Toast.LENGTH_LONG).show();
bundle.putString("cb",sb.toString());
//存入数据
intent.putExtras(bundle);
//跳转Activity
startActivity(intent);
break;
case R.id.bt_go:
//判断账号密码是否是admin
if(ed_username.getText().toString().equals("admin") && ed_password.getText().toString().equals("admin")){
Toast.makeText(MainActivity.this,"登录成功!",Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(MainActivity.this,"账户或密码错误!!",Toast.LENGTH_SHORT).show();
}
}
}
}
整体代码都差不多完成了,但是我们跳转后页面的代码也不能少了!主要就是取到上一个页面传来的值,取出并赋值给当前的控件显示出来!
package com.example.administrator.pj_001;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.TextView;
public class Client extends Activity{
private TextView tv_cname;
private TextView tv_cage;
private TextView tv_ctime;
private TextView tv_cemail;
private TextView tv_ccb;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.client);
//初始化控件
initView();
//获取传过来的值
Bundle bundle = this.getIntent().getExtras();
//取出获取的值并赋值给控件
tv_cname.setText(bundle.getString("name"));
tv_cage.setText(bundle.getString("age"));
tv_ctime.setText(bundle.getString("time"));
tv_cemail.setText(bundle.getString("email"));
tv_ccb.setText(bundle.getString("cb"));
}
//初始化控件
public void initView(){
tv_cname = findViewById(R.id.tv_cname);
tv_cage = findViewById(R.id.ctv_cage);
tv_ctime = findViewById(R.id.tv_ctime);
tv_cemail = findViewById(R.id.tv_cemail);
tv_ccb = findViewById(R.id.tv_ccb);
}
}