首页 > 其他分享 >3月9号Android开发学习

3月9号Android开发学习

时间:2023-03-11 14:35:08浏览次数:37  
标签:enable but 学习 开发 按钮 test import Android id

禁用与恢复按钮

在实际业务中按钮通常有两种状态,不可用状态和可用状态,它们的区别如下:

(1)不可用按钮:按钮不允许点击,即使点击也没有反映,同时按钮文字为灰色

(2)可用按钮:按钮允许点击,点击按钮会触发点击事件,同时按钮文字为正常的黑色

是否允许点击由enabled属性控制,属性值为true时表示允许点击,为false时表示不允许点击

 

 

<?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">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <Button
            android:id="@+id/but_enable"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:text="启用测试按钮"
            android:textColor="#000000"
            android:textSize="17dp"></Button>

        <Button
            android:id="@+id/but_disable"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:text="禁用测试按钮"
            android:textColor="#888888"
            android:textSize="17dp"></Button>
    </LinearLayout>

    <Button
        android:id="@+id/but_test"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="测试按钮"
        android:textColor="#000000"
        android:textSize="17dp"
        android:enabled="false"></Button>

    <TextView
        android:id="@+id/tv_result"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="查看测试按钮的结果"
        android:textColor="#000000"
        android:textSize="17dp"></TextView>

</LinearLayout>
package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

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

import com.example.myapplication.util.DateUtil;

public class ButtonEnableActivity extends AppCompatActivity implements View.OnClickListener {

    private Button but_enable;
    private Button but_disable;
    private Button but_test;
    private TextView tv_result;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_button_enable);
        but_enable = findViewById(R.id.but_enable);
        but_disable = findViewById(R.id.but_disable);
        but_test = findViewById(R.id.but_test);
        tv_result = findViewById(R.id.tv_result);

        but_enable.setOnClickListener(this);
        but_disable.setOnClickListener(this);
        but_test.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch(view.getId())
        {
            case R.id.but_enable:
                but_test.setEnabled(true);
                but_test.setTextColor(Color.BLACK);
                break;
            case R.id.but_disable:
                but_test.setEnabled(false);
                but_test.setTextColor(Color.GRAY);
                break;
            case R.id.but_test:
                String desc =String.format("%s", DateUtil.getNowTime());
                tv_result.setText(desc);
                break;
        }
    }
}

 

标签:enable,but,学习,开发,按钮,test,import,Android,id
From: https://www.cnblogs.com/cinan/p/17205789.html

相关文章

  • Gin学习笔记--多数据格式返回请求结果
    一个完整的请求包含请求,处理请求和结果返回三个步骤,在服务器端对请求处理完成后,会将结果返回给前端。1.[]byte通过context.Writer.Write方法写入[]byte数据。Writer是gin......
  • 学习日记-Day5
    日期2023-3-10任务列表离散数学第六章【100%】leetcode回溯算法x2、动态规划x4明天计划计网复习TCP、IP、HTTP协议巩固数据库和软工知识综合面问题离......
  • go学习 day207 继承
    编写一个学生考试系统packagemainimport( "fmt")//编写一个学生考试系统typestudentstruct{ Namestring Ageint Scoreint}//将Pupil和Graduate......
  • 学习分享:对极几何、基本矩阵、本质矩阵(持续更新)
    对极几何、基本矩阵、本质矩阵目录对极几何、基本矩阵、本质矩阵1对极约束1.2对极约束的理解2基本矩阵-Fundamental(对极约束的代数表示)2.1基本矩阵的几何推导2.2基......
  • 实验1 pyhton开发环境使用和编程初体验
    实验任务1task1:task1-1源码:1#print输出的几种用法23#用法1:用于输出单个字符串或单个变量4print('hey,u')56#用法2:用于输出多个数据项,用逗号分隔......
  • 开发直播app整体流程功能概览
    一、完整直播app原理直播原理: 把主播录制的视频,推送到服务器,在由服务器分发给观众观看。 直播环节:推流端(采集、美颜处理、编码、推流)服务端处理(转码、录制、截图......
  • 3月9号Android开发学习
    按钮控件Button按钮控件Button由TextView派生而来,他们之间的区别有:(1)Button拥有默认的按钮背景,而TextView默认无背景(2)Button内部文本默认居中对齐,而TextView的内部......
  • kernel logo到开机动画之间闪现黑屏(android 5.X)
    在BootAnimation开始绘图之前,会先做一次clearscreen的动作,避免出现前面的图干扰到BootAnimation的显示。通过checkmain_log先确认播放开机动画是哪个function,在对应functi......
  • android 在图库中进行幻灯片播放时图片不会全屏显示
    1.在Slideshowview.java2.@Overridepublicvoidapply(GLCanvascanvas){intviewWidth=getWidth();intviewHeight=......
  • android 中如何获取IMEI号
    1)在TelephonyFramework内部,可以直接使用GSMPhone或GeminiPhone提供的接口。KK之前的版本:IMEI(InternationalMobileEquipmentIdentity)是国际移动设备身份码,在单卡工程......