android | 出题模板

为了方便以后出题,写了个模板。

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:id="@+id/txt1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="TextView(显示框)"
        android:textStyle="bold|italic"
        android:textSize="18sp" />

    <EditText
        android:id="@+id/edit1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="text"
        android:hint="请输入flag"
        android:textColorHint="#95A1AA"/>

    <Button
        android:id="@+id/btn1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="check!"/>


</LinearLayout>

MainActivity.java:

package com.example.crackme1;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private Button btn1;
    private TextView txt1;
    private EditText edit1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init_widget();
    }

    private void init_widget(){
        btn1 = (Button)findViewById(R.id.btn1);
        txt1 = (TextView)findViewById(R.id.txt1);
        edit1 = (EditText)findViewById(R.id.edit1);
        txt1.setText("Welcome to Crackme1");
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String tmp = edit1.getText().toString();
                txt1.setText(tmp);
                Boolean b = Check.check(tmp);
                if (b){
                    Toast ts = Toast.makeText(getBaseContext(),"you are right~", Toast.LENGTH_LONG);
                    ts.show();
                }else{
                    Toast ts = Toast.makeText(getBaseContext(),"Wrong!", Toast.LENGTH_LONG);
                    ts.show();
                }
            }
        });
    }
}

native层出题模板:

package com.example.crackmen1;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private Button btn1;
    private TextView txt1;
    private EditText edit1;

    static {
        System.loadLibrary("native-lib");
    }
    public native String stringFromJNI();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init_widget();
    }

    private void init_widget(){
        btn1 = (Button)findViewById(R.id.btn1);
        txt1 = (TextView)findViewById(R.id.txt1);
        edit1 = (EditText)findViewById(R.id.edit1);
        txt1.setText(stringFromJNI());
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String tmp = edit1.getText().toString();
                txt1.setText(tmp);
                Boolean b = Check.check(tmp);
                if (b){
                    Toast ts = Toast.makeText(getBaseContext(),"you are right~", Toast.LENGTH_LONG);
                    ts.show();
                }else{
                    Toast ts = Toast.makeText(getBaseContext(),"Wrong!", Toast.LENGTH_LONG);
                    ts.show();
                }
            }
        });
    }
}
posted @ 2021-09-08 16:33  Mz1  阅读(54)  评论(0编辑  收藏  举报