事件

本文主要讲述了在Android应用中如何设置按钮的英文文本默认为大写,以及如何添加点击和长按事件,还提及了ImageView的使用。

1.按钮 

 现在默认是正常了 ,英文

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="5dp">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="下面的按钮英文默认大写"
        android:textColor="@color/black"
        android:gravity="center"
        android:textSize="17sp"/>


    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Hello Word"/>



</LinearLayout>

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="5dp">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="下面的按钮英文默认大写"
        android:textColor="@color/black"
        android:gravity="center"
        android:textSize="17sp"/>
    <TextView
        android:id="@+id/tv_result"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="点击按钮查看结果"
        android:textColor="@color/black"
        android:textSize="17sp"/>


    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAllCaps="true"
        android:textColor="@color/black"
        android:textSize="17sp"
        android:text="Hello Word"
     />
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAllCaps="true"
        android:textColor="@color/black"
        android:textSize="17sp"
        android:text="直接指定点击方法"
        android:onClick="doClick"
        />


</LinearLayout>
package com.tiger.chapter03;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import java.util.Date;

public class GridLayoutActivity extends AppCompatActivity {

    private TextView tv_result;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scroll_view);
        tv_result = findViewById(R.id.tv_result);
    }

    public void doClick(View view){
        Button button = (Button) view;
        tv_result.setText(button.getText()+"点击了按钮:"+new Date().toString());
    }
}

2.点击事件和长按事件 

 

 3.图像ImageView

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值