AndroidStudio点击按钮实现页⾯跳转、⽹页跳转0)提⽰
页⾯跳转时出现⿊屏闪退的情况,可以参考
⽹页跳转需要⼿机联⽹,可以参考,如果还不⾏的话,换成⾼版本的模拟机再试试
1)页⾯跳转
Btn1=findViewById(R.id.btn_1);
Btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(MainActivity.this,nextActivity.class);
startActivity(intent);
}
});
2)⽹页跳转
Btn2=findViewById(R.id.btn_2);
final Uri uri=Uri.parse("homeblogs/u/kori/");
Btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(Intent.ACTION_VIEW,uri);
startActivity(intent);
}
});
3)完整代码
免费下载文件的网站l:
<?xml version="1.0" encoding="utf-8"?>
&straintlayout.widget.ConstraintLayout xmlns:android="schemas.android/apk/res/android"
建立二叉树的代码c语言xmlns:app="schemas.android/apk/res-auto"
next studioxmlns:tools="schemas.android/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/btn_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="JUMP"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.529"
nuthatchapp:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.382" />
<Button
android:id="@+id/btn_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="120dp"
android:text="WEB"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.529"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_1" />
</straintlayout.widget.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
&straintlayout.widget.ConstraintLayout
xmlns:android="schemas.android/apk/res/android"
xmlns:app="schemas.android/apk/res-auto"
xmlns:tools="schemas.android/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SUCCESS!"
android:textStyle="bold"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</straintlayout.widget.ConstraintLayout>
MainActivity.java:
ample.jumpto;
import androidx.appcompat.app.AppCompatActivity;
t.Intent;
import android.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button Btn1,Btn2;
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
Btn1=findViewById(R.id.btn_1);
Btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(MainActivity.this,nextActivity.class);                startActivity(intent);
}
激素胖是什么意思});
Btn2=findViewById(R.id.btn_2);
final Uri uri=Uri.parse("homeblogs/u/kori/");
Btn2.setOnClickListener(new View.OnClickListener() {
111110二进制转换十进制
@Override
public void onClick(View v) {
Intent intent=new Intent(Intent.ACTION_VIEW,uri);
startActivity(intent);
}
});
}
}
nextActivity.java:
ample.jumpto;
import android.os.Bundle;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
public class nextActivity extends AppCompatActivity {
Button Btn1;
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView();
}
}
4)结果呈现

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。