android闹钟开发详解总结

本文详细介绍了如何在Android平台上开发一个闹钟应用,包括布局文件`main.xml`的创建,使用`AnalogClock`、`DigitalClock`、`Button`和`TextView`等组件,以及`MainActivity.java`中按钮点击事件的实现,设置和取消闹钟的逻辑。此外,还涉及到`CallAlarm`广播接收者和`Alarmalert`提示界面的创建,以及如何在应用退出后保存和恢复闹钟设置。文章最后提到了AndroidManifest.xml中对服务的注册,并提供了源码下载链接。
摘要由CSDN通过智能技术生成

android也有一段时间了,之前一直在看基础,后面想想或许做一个实例出来会明白的更多;

然后弄了一个android的闹钟,也在网上找了许多闹钟的实例,在开始的时候看着都不是很明白,再加上那些实例基本没什么注释,后面也发现了一些好的简单的实力,好了.废话不多说,现在来总结一下我的android闹钟吧.

 

界面:

 

 

做一个闹钟,先要弄好布局文件:mian.xml

需要用到的控件有 Button  TextView  DigitalClock  AnalogClock

ButtonTextView就不多说了, DigitalClock是用于显示数字的时间的, AnalogClock是用于显示图表的时间,下面是main.xml的代码:

<?xmlversion="1.0"encoding="utf-8"?>

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:orientation="vertical"

    android:background="@drawable/black"

     >

 

    <AnalogClock

        android:id="@+id/analogClock"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"/>

 

    <DigitalClock

        android:gravity="center"

        android:id="@+id/dclock"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_x="30px"

        android:layout_y="32px"

        android:textSize="55sp"/>

 

    <LinearLayout

        xmlns:android="http://schemas.android.com/apk/res/android"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:orientation="horizontal">

 

        <TextView

            android:id="@+id/textview2"

            android:layout_width="160dp"

            android:layout_height="wrap_content"

            android:gravity="right"

            android:text="起床闹钟设置为:"/>

 

        <TextView

            android:id="@+id/textview1"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:gravity="center_vertical"

            android:text="@string/hello"/>

 

    </LinearLayout>

   

        <LinearLayout

        xmlns:android="http://schemas.android.com/apk/res/android"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:orientation="horizontal">

 

    <Button

        android:gravity="center"

        android:layout_weight

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值