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();
}
}
});
}
}
本文来自博客园,作者:Mz1,转载请注明原文链接:https://www.cnblogs.com/Mz1-rc/p/15243365.html
如果有问题可以在下方评论或者email:mzi_mzi@163.com