Android時(shí)間選擇器示例含代碼

Android時(shí)間選擇器示例

Android時(shí)間選擇器 小部件用于選擇日期。愛掏網(wǎng) - it200.com它允許你按小時(shí)和分鐘選擇時(shí)間。愛掏網(wǎng) - it200.com你不能按秒選擇時(shí)間。愛掏網(wǎng) - it200.com

android.widget.TimePicker是FrameLayout類的子類。愛掏網(wǎng) - it200.com

Android時(shí)間選擇器示例

讓我們看一個(gè)簡(jiǎn)單的Android時(shí)間選擇器示例。愛掏網(wǎng) - it200.com

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>  
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    xmlns:app="http://schemas.android.com/apk/res-auto"  
    xmlns:tools="http://schemas.android.com/tools"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent"  
    tools:context="example.javatpoint.com.timepicker.MainActivity">  

    <TextView  
        android:id="@+id/textView1"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_above="@+id/button1"  
        android:layout_alignParentLeft="true"  
        android:layout_alignParentStart="true"  
        android:layout_marginBottom="102dp"  
        android:layout_marginLeft="30dp"  
        android:layout_marginStart="30dp"  
        android:text="" />  

    <Button  
        android:id="@+id/button1"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_alignParentBottom="true"  
        android:layout_centerHorizontal="true"  
        android:layout_marginBottom="20dp"  
        android:text="Change Time" />  

    <TimePicker  
        android:id="@+id/timePicker"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_above="@+id/textView1"  
        android:layout_centerHorizontal="true"  
        android:layout_marginBottom="36dp" />  
</RelativeLayout>  

Activity類

package example.javatpoint.com.timepicker;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;

public class MainActivity extends AppCompatActivity {
    TextView textview1;
    TimePicker timepicker;
    Button changetime;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textview1=(TextView)findViewById(R.id.textView1);
        timepicker=(TimePicker)findViewById(R.id.timePicker);
        //Uncomment the below line of code for 24 hour view
        timepicker.setIs24HourView(true);
        changetime=(Button)findViewById(R.id.button1);

        textview1.setText(getCurrentTime());

        changetime.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                textview1.setText(getCurrentTime());
            }
        });

    }

    public String getCurrentTime(){
        String currentTime="Current Time: "+timepicker.getCurrentHour()+":"+timepicker.getCurrentMinute();
        return currentTime;
    }

}

輸出:

聲明:所有內(nèi)容來(lái)自互聯(lián)網(wǎng)搜索結(jié)果,不保證100%準(zhǔn)確性,僅供參考。如若本站內(nèi)容侵犯了原著者的合法權(quán)益,可聯(lián)系我們進(jìn)行處理。
發(fā)表評(píng)論
更多 網(wǎng)友評(píng)論0 條評(píng)論)
暫無(wú)評(píng)論

返回頂部

主站蜘蛛池模板: a毛片免费全部在线播放**| 久久综合久久鬼| 天天色天天射天天干| 韩国一级免费视频| 亚洲av中文无码乱人伦在线观看 | 国产激情电影综合在线看| 97久久天天综合色天天综合色| 伊人久久大香网| 很黄很色裸乳视频网站| 美女张开腿让男人桶爽国产| 久久人人爽爽爽人久久久| 国产成人免费网站app下载| 日韩精品无码一本二本三本| 一区二区三区四区视频在线| 可以直接看的毛片| 性做久久久久久久久| 色偷偷91久久综合噜噜噜| 亚洲欧美成aⅴ人在线观看| 日韩丰满少妇无码内射| а天堂中文在线官网在线| 俺去啦在线视频| 国产又黄又爽又刺激的免费网址| 国产精品无码久久av| 夜夜高潮天天爽欧美| 性欧美18-19sex性高清播放| 日本中文字幕在线视频| 粉色视频在线播放| 精品长泽梓在线播放视频| 蜜臀av无码人妻精品| 西西大胆午夜人体视频| 香港国产特级一级毛片| www.夜夜操.com| 一本色道久久88| 亚洲av永久精品爱情岛论坛| 亚洲日产2021三区| 亚洲欧美一区二区三区| 嘿咻视频免费网站| 午夜爽爽爽男女免费观看hd| 午夜精品久久久久久久| 办公室啪啪激烈高潮动态图| 国产片免费在线观看|