tampurus

Android Ramesh

Sep 3rd, 2024
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. [03/09, 09:29] +91 96696 84556: main_activity.java
  2. [03/09, 09:29] +91 96696 84556: xml_file
  3. [03/09, 09:29] +91 96696 84556: package com.example.mybuttonapp;
  4.  
  5. import android.content.Intent;
  6. import android.os.Bundle;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.TextView;
  10.  
  11. import androidx.activity.EdgeToEdge;
  12. import androidx.appcompat.app.AppCompatActivity;
  13. import androidx.core.graphics.Insets;
  14. import androidx.core.view.ViewCompat;
  15. import androidx.core.view.WindowInsetsCompat;
  16.  
  17. public class MainActivity extends AppCompatActivity {
  18. //1 st create two variables (text and button)
  19.  
  20.  
  21. @Override
  22. protected void onCreate(Bundle savedInstanceState) {
  23. super.onCreate(savedInstanceState);
  24. EdgeToEdge.enable(this);
  25. setContentView(R.layout.activity_main);
  26. Button button =findViewById(R.id.secondActivityButton);
  27.  
  28. ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
  29. Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
  30. v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
  31. return insets;
  32. });
  33. // 2 nd step link created variables with RefID;
  34. button.setOnClickListener(new View.OnClickListener() {
  35. @Override
  36. public void onClick(View view) {
  37. Intent intent = new Intent(MainActivity.this,SecondAcitivity.class);
  38. startActivity( intent);
  39. }
  40.  
  41.  
  42.  
  43. });
  44.  
  45. // 3 rd step : Create action for button click;
  46.  
  47.  
  48. }
  49.  
  50.  
  51. }
  52. [03/09, 09:29] +91 96696 84556: =========
  53. [03/09, 09:29] +91 96696 84556: <?xml version="1.0" encoding="utf-8"?>
  54. <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  55. xmlns:app="http://schemas.android.com/apk/res-auto"
  56. xmlns:tools="http://schemas.android.com/tools"
  57. android:id="@+id/main"
  58. android:layout_width="match_parent"
  59. android:layout_height="match_parent"
  60. tools:context=".MainActivity">
  61.  
  62.  
  63. <Button
  64. android:id="@+id/secondActivityButton"
  65. android:layout_width="wrap_content"
  66. android:layout_height="wrap_content"
  67. android:autoSizeStepGranularity="@android:dimen/app_icon_size"
  68. android:text="GO TO MY SECOND ACTIVITY"
  69. app:layout_constraintBottom_toBottomOf="parent"
  70. app:layout_constraintEnd_toEndOf="parent"
  71. app:layout_constraintStart_toStartOf="parent"
  72. app:layout_constraintTop_toTopOf="parent" />
  73. </androidx.constraintlayout.widget.ConstraintLayout>
  74. [03/09, 09:29] +91 96696 84556: package com.example.mybuttonapp;
  75.  
  76. import android.os.Bundle;
  77.  
  78. import androidx.activity.EdgeToEdge;
  79. import androidx.appcompat.app.AppCompatActivity;
  80. import androidx.core.graphics.Insets;
  81. import androidx.core.view.ViewCompat;
  82. import androidx.core.view.WindowInsetsCompat;
  83.  
  84. public class SecondAcitivity extends AppCompatActivity {
  85.  
  86. @Override
  87. protected void onCreate(Bundle savedInstanceState) {
  88. super.onCreate(savedInstanceState);
  89. EdgeToEdge.enable(this);
  90. setContentView(R.layout.activity_second_acitivity);
  91. ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
  92. Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
  93. v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
  94. return insets;
  95. });
  96. }
  97. }
  98. [03/09, 09:29] +91 96696 84556: secondActivity_xml
Advertisement
Add Comment
Please, Sign In to add comment