码迷,mamicode.com
首页 > 移动开发 > 详细

1_1.7_hello_android

时间:2019-01-09 13:45:29      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:contex   ext   cal   rri   out   ati   imp   long   ack   

------------------------------------------------------

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.681"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.142" />

<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="确定"
tools:layout_editor_absoluteX="174dp"
tools:layout_editor_absoluteY="447dp" />

</android.support.constraint.ConstraintLayout>

 

 

 

-------------------------------------------------------

MainActivity.java

package com.example.init.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


Button btn = findViewById(R.id.btn1);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(),"hi.it is me",Toast.LENGTH_LONG).show();
}
});

}
}

1_1.7_hello_android

标签:contex   ext   cal   rri   out   ati   imp   long   ack   

原文地址:https://www.cnblogs.com/bj-tony/p/10243472.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!