package com.example.myapplication;
import android.app.TimePickerDialog;
import android.os.Bundle;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
import java.sql.Time;
public class MainActivity extends AppCompatActivity {
public int beginHour =0;
private TextView tv ;
final Handler mHandler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(@NonNull Message msg) {
String s = (String) msg.obj;
Log.d("ddd", "ddddddddddddddddddddd" + s);
updateView(s);
return true; //返回true就不会执行Handler自己的handleMessage方法了
}
});
void updateView(String s){
tv.setText("xianzai shij , " + Integer.toString(beginHour) );
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Log.d("ddd", "ddddddddddddddddddddd");
tv = findViewById(R.id.textview_first);
// Button bt = findViewById(R.id.testtime);
// Button btfir = findViewById(R.id.button_first);
//
//
// btfir.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// Log.d("ddd", "btffffist ");
// }
// });
FloatingActionButton fab = findViewById(R.id.fab);
Toast.makeText(MainActivity.this,"dfdfdfd",Toast.LENGTH_LONG).show();
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
// .setAction("Action", null).show();
Log.d("ddd", "qqqqqq");
TimePickerDialog tp = new TimePickerDialog(MainActivity.this,android.R.style.Theme_Holo_Light_Dialog_NoActionBar, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int i, int i1) {
beginHour = i;
Message message = new Message();
String s = "第条消息";
message.obj = s;
mHandler.sendMessage(message);
}
},9 ,0 ,true);
tp.show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}