设为首页 加入收藏

TOP

[APP] Android 开发笔记 004-Android常用基本控件使用说明(四)
2017-10-13 10:47:29 】 浏览:11618
Tags:APP Android 开发 笔记 004-Android 常用 基本 控件 使用说明
sp;           editText = (EditText) findViewById(R.id.edit);
                text = (TextView) findViewById(R.id.text);
         
                text.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        text.setText(editText.getText());;
                    }
                });
         
            }

        text.setOnClickListener()方法是text监听方法.用来监听TextView的点击事件。
        整个流程就是在输入文本后点击text然后text的文本就会被替换成你输入的文本.


Button 与 ImageButton


    本节学习Android基本控件按钮控件,Button和ImageButton用法基本类似,所以本节重点讲解Button控件。

    1)代码:

       <Button
            android:id="@+id/btn"
            android:text="普通按钮"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    2)Button的其他常用属性:

    -background 背景 可以是颜色或者图片或这xml资源
    -text        按钮显示的文字
    -textColor    按钮文字颜色
    -textSize    按钮文字大小

    3)Button控件的绑定和监听:

    绑定

        btn = (Button) findViewById(R.id.btn);

    监听的方法很常用

                btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(MainActivity.this , "button 被按下" , Toast.LENGTH_LONG).show();
                }
            });

    4)Toast方法是常

首页 上一页 1 2 3 4 5 6 7 下一页 尾页 4/8/8
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Android---闪频页和倒计时 下一篇微信支付仅能成功调用一次的问题

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目