Android学习(2)---Android基本控件的学习

内容概要

上次用markdown写了一篇,结果感觉排版是一塌糊涂,,,于是对这个东西的印象十分的不好,当然也可能是我不熟悉、不会用的原因,但是,暂且不使用这个MarkDown了,使用CSDN哪个普通的写出来的,样式应该更好看一些;
这篇博客主要用来记录Android基本组件的学习,4大核心组件就先不说了,Activity、Service、BroadcastReceiver、ContentProvider,intent也不说了,目前使用过的最多的也就是Activity了,还有intent,对于其他3个核心组件还没有写过代码,需要进一步的学习,本篇是跟着极客学院的视频来的,由页面布局开始,记录下常用控件的使用情况,将这些控件都放到一个小的demo项目中,由listView来包裹,点击展示各个控件的样式与基本使用。

控件列表

  • RadioGroup
  • CheckBox
  • DatePicker
  • TimePicker
  • Spinner
  • ProgressBar
  • SeekBar
  • RatingBar
  • GridView
  • ScorllView
  • ProgressDialog
  • Notification
  • Gallery
  • ImageSwitcher
  • AutoCompleteTextView
  • EditText
列表展示图:


DEMO源码:

百度网盘地址: BasicWeights

一些关键代码

  1. RadioGroup和CheckBox的关键属性:isChecked
  2. DatePickerDialog 和 TimePickerDialog 的使用代码
<span style="white-space:pre">		</span>new DatePickerDialog(DatePickerAty.this, new DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePicker datePicker, int year, int monthOfYear, int dayOfMonth) {

                        datepickerbtn.setText(String.format("%d:%d:%d", year, monthOfYear, dayOfMonth));
                    }
                }, 2015, 12, 5).show();

<span style="white-space:pre">		</span>new TimePickerDialog(TimePickerAty.this, new TimePickerDialog.OnTimeSetListener() {
                    @Override
                    public void onTimeSet(TimePicker timePicker, int hourOfDay, int minite) {

                        timepickerbtn.setText(String.format("%s:%s", timeFormat(hourOfDay), timeFormat(minite)));
                    }
                }, 11, 34, true).show();
3. Spinner关键方法:setAdapter
4. ProgressBar:setMax setProgress
5. SeekBar:setOnSeekBarChangeListener
6. ProgressDialog:
public class ProgressDialogAty extends Activity {

    private Button progressdialogshow;
    private ProgressDialog progressDialog;

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

        progressdialogshow = (Button) findViewById(R.id.progressdialogshow);
        progressdialogshow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                progressDialog = ProgressDialog.show(ProgressDialogAty.this,"加载","正在加载。。。");

                new Thread() {

                    @Override
                    public void run() {
                        try {
                            Thread.sleep(3000);
                            progressDialog.dismiss();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }

                    }
                }.start();
            }
        });
    }
}
7. Notification:视频中还是使用的老的方法来实现的,我更喜欢新的方法,该淘汰的就淘汰吧
public class NotificationAty extends Activity {

    private Button notificationshow;

    private Notification n;
    private NotificationManager nm;

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

        nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationshow = (Button) findViewById(R.id.notificationshow);

        notificationshow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                // Notification n = new Notification(R.drawable.notification,"Ticker Text",System.currentTimeMillis());

                // This method was removed in M (api 23). So if your compile SDK version is set to api 23+ you'll see this issue.

                // n.setLatestEventInfo(NotificationAty.this, "title", "content", PendingIntent.getActivity(NotificationAty.this, 1, getIntent(), 0));
                // nm.notify(R.layout.aty_using_notification, n);



                // Intent intent = new Intent("com.rj.notitfications.SECACTIVITY");
                PendingIntent pendingIntent = PendingIntent.getActivity(NotificationAty.this, 1, getIntent(), 0);

                Notification.Builder builder = new Notification.Builder(NotificationAty.this);

                builder.setAutoCancel(true);
                builder.setTicker("状态栏提示信息Tick");
                builder.setContentTitle("通知标题");
                builder.setContentText("通知内容");
                builder.setSmallIcon(R.drawable.notification); // 这个地方设置的图片不知道为什么不起作用;
                builder.setContentIntent(pendingIntent);
                builder.setOngoing(true);
                // builder.setSubText("This is subtext...");   //API level 16
                builder.setNumber(100);
                // builder.build();

                n = builder.getNotification();
                nm.notify(R.layout.notification_aty, n);

            }
        });

    }
}


 总结

基本控件的使用暂且写这些吧,应该还有些控件没有涉及到,待到使用的时候再看应该也不是很迟,这些个控件的文档也还没有读过,还需要再看一下,总之有这么个小demo,必要的时候也好拿来抄一下 奋斗

edit by zhang.xx 2015年12月23日14:47:39



















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值