今日总结
今日学习时间依然2h
package com.app.chapter03;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import com.app.chapter03.utils.DateUtil;
public class ButtonLongClickActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_button_long_click);
Button btn_long_click_single = findViewById(R.id.btn_long_click_single);
Button btn_tiaozhuan =findViewById(R.id.btn_tiaozhuan);
btn_tiaozhuan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent= new Intent();
intent.setClass(ButtonLongClickActivity.this,ScrollViewActivity.class);
startActivity(intent);
}
});
// TextView tv_result = findViewById(R.id.tv_result);
// btn_long_click_single.setOnClickListener(v -> {
// String desc =String.format("%s 您点击了按钮: %s", DateUtil.getNowTime(), ((Button)v).getText());
// tv_result.setText(desc);
//
// });
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical">
<Button
android:id="@+id/btn_long_click_single"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="指定长按的点击监听器"
android:textColor="#000000"
android:textSize="15sp"/>
<TextView
android:id="@+id/tv_result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:gravity="center"
android:textColor="#000000"
android:textSize="15sp"
android:text="这里查看按钮的点击结果"/>
<Button
android:layout_gravity="center"
android:layout_marginTop="100dp"
android:id="@+id/btn_tiaozhuan"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="跳转界面"
android:textColor="#000000"
android:textSize="15sp"/>
</LinearLayout>
标签:layout,androidx,5.27,import,android,btn,id From: https://www.cnblogs.com/tianpeisen/p/18250881
}
}