Android——圖片視圖(ImageView)、狀態開關按鈕(ToggleButton)、時鐘、圖片透明度、滾動和時間選取器

來源:互聯網
上載者:User

標籤:

activity_ui1.xml

dth="wrap_content"        android:layout_height="wrap_content"        android:textOn=" "        android:textOff=" "        android:background="@drawable/qq"        android:id="@+id/tob1"/>    <AnalogClock        android:layout_width="wrap_content"        android:layout_height="wrap_content" />    <DigitalClock        android:layout_width="wrap_content"        android:layout_height="wrap_content" />    <DatePicker        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:startYear="2000"        android:endYear="2016"        android:minDate="1/1/2000"        android:maxDate="12/31/2016"        android:id="@+id/dp_1"        android:calendarViewShown="false"        android:spinnersShown="false">        <!--startYear選擇開始年        endYear   選擇結束年        minDate  開始時間        maxDate  結束時間        calendarViewShown  日曆是否顯示 只對版本4 起作用        spinnersShown   是否下拉        -->    </DatePicker>    <TimePicker        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:id="@+id/tp_1">    </TimePicker>    <!--AnalogClock時鐘錶盤    DigitalClock  數字時鐘    DatePicker 日期選取器    TimePicker  時間選取器    CalendarView  顯示日曆  版本4  不支援    -->    <CalendarView        android:layout_width="match_parent"        android:layout_height="match_parent"        android:firstDayOfWeek="1">    </CalendarView></LinearLayout></ScrollView>

在drawable目錄中的qq.xml

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:drawable="@drawable/on" android:state_checked="true"/>    <item android:drawable="@drawable/off" android:state_checked="false"/>    </selector>

UIActivity1.java

package com.hanqi.application3;import android.app.Activity;import android.os.Bundle;import android.support.annotation.IdRes;import android.widget.CheckBox;import android.widget.CompoundButton;import android.widget.DatePicker;import android.widget.ImageView;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.Switch;import android.widget.TimePicker;import android.widget.Toast;import android.widget.ToggleButton;import static android.widget.CompoundButton.*;public class UIActivity1 extends Activity {    ImageView iv;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_ui1);        RadioGroup radioGroup = (RadioGroup)findViewById(R.id.rb);        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {                if (checkedId == R.id.rb3) {                    Toast.makeText(UIActivity1.this, "選對了", Toast.LENGTH_SHORT).show();                }                RadioButton rb = (RadioButton) findViewById(checkedId);                Toast.makeText(UIActivity1.this, rb.getText(), Toast.LENGTH_SHORT).show();            }        });        CheckBox cb_st= (CheckBox)findViewById(R.id.cb_st);        cb_st.setOnCheckedChangeListener(new CBOnCheckChangeListenter());        CheckBox cb_xt= (CheckBox)findViewById(R.id.cb_xt);        cb_xt.setOnCheckedChangeListener(new CBOnCheckChangeListenter());        CheckBox cb_jc= (CheckBox)findViewById(R.id.cb_jc);        cb_jc.setOnCheckedChangeListener(new CBOnCheckChangeListenter());        CheckBox cb_xhx= (CheckBox)findViewById(R.id.cb_xhx);        cb_xhx.setOnCheckedChangeListener(new CBOnCheckChangeListenter());        iv= (ImageView)findViewById(R.id.iv);        ToggleButton tob = (ToggleButton)findViewById(R.id.tob);        tob.setOnCheckedChangeListener(new TOncheckchangeLitenter() );        Switch sw = (Switch)findViewById(R.id.sw);        //初始化        DatePicker dp_1= (DatePicker)findViewById(R.id.dp_1);        //月份是從0開始的        dp_1.init(2000, 1, 1, new DatePicker.OnDateChangedListener() {            @Override            public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {                Toast.makeText(UIActivity1.this, year+"-"+(monthOfYear+1)+"-"+dayOfMonth, Toast.LENGTH_SHORT).show();            }        });        TimePicker tp_1= (TimePicker)findViewById(R.id.tp_1);        Toast.makeText(UIActivity1.this, dp_1.getYear()+"-"+(dp_1.getMonth()+1)+"-"+dp_1.getDayOfMonth()                +" "+tp_1.getHour()+":"+tp_1.getMinute(), Toast.LENGTH_SHORT).show();        tp_1.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {            @Override            public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {                Toast.makeText(UIActivity1.this, hourOfDay+":"+minute, Toast.LENGTH_SHORT).show();            }        });    }    private class TOncheckchangeLitenter implements OnCheckedChangeListener    {        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {            if (isChecked)            {                iv.setImageResource(R.drawable.open);            }            else            {                iv.setImageResource(R.drawable.close);            }        }    }    private class CBOnCheckChangeListenter implements OnCheckedChangeListener    {        @Override        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {            CheckBox cb = (CheckBox)buttonView;            if (isChecked) {                Toast.makeText(UIActivity1.this, "選中了", Toast.LENGTH_SHORT).show();            }            else            {                Toast.makeText(UIActivity1.this, "取消了", Toast.LENGTH_SHORT).show();            }        }    }}

 

Android——圖片視圖(ImageView)、狀態開關按鈕(ToggleButton)、時鐘、圖片透明度、滾動和時間選取器

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.