Add previous page

This commit is contained in:
icewithcola 2024-03-26 08:45:49 +08:00
parent 57c519cf45
commit 1f5dfeaf23
6 changed files with 82 additions and 5 deletions

View file

@ -12,6 +12,9 @@
android:supportsRtl="true"
android:theme="@style/Theme.Android101"
tools:targetApi="31">
<activity
android:name=".Page3"
android:exported="false" />
<activity
android:name=".MainActivity2"
android:exported="false" />
@ -19,8 +22,9 @@
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

View file

@ -1,10 +1,12 @@
package uk.kagurach.android101;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
@ -29,6 +31,14 @@ public class MainActivity2 extends AppCompatActivity {
Log.d("K","2");
}
@Override
protected void onResume(){
super.onResume();
Button button = findViewById(R.id.next_page_nav_2);
button.setOnClickListener(new PageButtonHandler());
button.setOnLongClickListener(new LongClickHandler());
}
public void set70sp(View view) {
TextView t = findViewById(R.id.test2strview);
@ -67,4 +77,31 @@ public class MainActivity2 extends AppCompatActivity {
}
}
}
public void goNext() {
Intent myIntent = new Intent(this, Page3.class);
startActivity(myIntent);
};
public void goPrev() {
Intent myIntent = new Intent(this, MainActivity.class);
startActivity(myIntent);
};
final class PageButtonHandler implements View.OnClickListener
{
@Override
public void onClick(View v){
goNext();
}
}
final class LongClickHandler implements View.OnLongClickListener
{
@Override
public boolean onLongClick(View v){
goPrev();
return false;
}
}
}

View file

@ -0,0 +1,24 @@
package uk.kagurach.android101;
import android.os.Bundle;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class Page3 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_page3);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
}
}

View file

@ -101,11 +101,12 @@
android:onClick="setColor"/>
<Button
android:id="@+id/button7"
android:id="@+id/next_page_nav_2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/next_page" />
android:text="@string/two_way_page"
/>
</LinearLayout>

View file

@ -0,0 +1,10 @@
<?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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Page3">
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -2,6 +2,7 @@
<string name="app_name">Android101</string>
<string name="hello_world">你好,世界!</string>
<string name="next_page">下一页</string>
<string name="two_way_page">单击下一页,长桉上一页</string>
<string name="test_str">测试文本</string>
<string name="set_color">设置颜色</string>
</resources>