小编Pra*_*dhi的帖子

时间选择器00:00:00 AM/PM格式,在android中有秒

在我的Time Tracking android项目中,我希望TimePicker具有秒字段.谷歌搜索后,我没有找到任何解决方案,最后我为Android制作了自定义TimePicker,它在00:00:00 AM/PM格式下给出了时间值.我认为这段代码对android开发人员有帮助,所以我将这段代码上传到Stack.

main.xml中

   <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
        <Button 
            android:text="Time"
            android:id="@+id/time_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            />
        <TextView               
            android:layout_centerInParent="true"
            android:id="@+id/time_txt"                 
            android:textStyle="bold"
            android:textSize="25dp"
            android:textColor="#ffffff"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            />            
    </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

customdialog.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="4dp"
        android:background="#ffffff"
         >            
        <RelativeLayout 
            android:id="@+id/first"
            android:layout_margin="2dp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#000000"
            >
            <ImageView 
                android:id="@+id/clock"
                android:layout_margin="2dp"
                android:src="@drawable/coggl_logo"
                android:layout_width="40dp"
                android:layout_height="40dp"
            />
            <TextView 
                android:id="@+id/actualtime"
                android:layout_toRightOf="@+id/clock"
                android:textColor="#ffffff"
                android:text="00:00:00 AM"
                android:textSize="25dp"
                android:textStyle="bold"
                android:layout_margin="5dp"       
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"    
            />           
        </RelativeLayout>
        <RelativeLayout 
            android:id="@+id/second"
            android:layout_below="@+id/first"
            android:layout_margin="2dp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#000000"
            android:paddingBottom="15dp"
        >
        <Button 
            android:id="@+id/plus1"
            android:layout_marginLeft="12dp"
            android:layout_marginRight="12dp" …
Run Code Online (Sandbox Code Playgroud)

android

7
推荐指数
0
解决办法
5538
查看次数

标签 统计

android ×1