1.switchermod怎么用
switchermod怎么用
一、各自的功能及使用场景
ImageView:用于展示一张,例如商品展示;
Switch:开关、法院源码控制器,常用于app设置中;
DatePicker:日期选择器,源码包括ui吗多用于订阅类的魏来 源码资本服务和功能
二、简单使用
1、布局部分
xml version="1.0" encoding="utf-8"?LinearLayout xmlns:android="/apk/res/android" xmlns:app="/apk/res-auto" xmlns:tools="/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:gravity="center" android:orientation="vertical" ImageView android:id="@+id/iv_img" android:layout_width="dp" android:layout_height="dp" / Button android:id="@+id/btn_todo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="CLICK"/ Switch android:id="@+id/s_toggle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true"/ TextView android:id="@+id/tv_date" android:layout_width="wrap_content" android:layout_height="wrap_content"/ DatePicker android:id="@+id/dp_date" android:layout_width="wrap_content" android:layout_height="wrap_content" //LinearLayoutcode>
2、代码部分
private TextView tvDate; private Button btnTodo; private Switch sToggle; private DatePicker dpDate; private ImageView ivImg; @Override protected void onCreate(Bundle savedInstanceState) private void setListener() ); sToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() }); if (Build.VERSION.SDK_INT = Build.VERSION_CODES.O) }); } } private void initView() }
code>
代码中,我通过sToggle来控制btnTodo是否可点击,将dpDate获取到的日期用tvDate展示,之所以会+1是因为月份获取到的数字是从0开始的
三、运行效果
四、定制网站源码价格官网对于上述控件的属性介绍
1、ImageView
android:adjustViewBounds
Set this 屈臣氏小程序源码to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable.
android:baseline
The offset of the baseline within this view.
android:baselineAlignBottom
If true, the image view will be baseline aligned with based on its bottom edge.
android:cropToPadding
If true, the image will be cropped to fit within its padding.
android:maxHeight
An optional argument to supply a maximum height for this view.
android:maxWidth
An optional argument to supply a maximum width for this view.
android:scaleType
Controls how the image should be resized or moved to match the size of this ImageView.
android:src
Sets a drawable as the content of this ImageView.
android:tint
The tinting color for the image.
android:tintMode
Blending mode used to apply the image tint.
2、Switch
android:showText
Whether to draw on/off text.
android:splitTrack
Whether to split the track and leave a gap for the thumb drawable.
android:switchMinWidth
Minimum width for the switch component.
android:switchPadding
Minimum space between the switch and caption text.
android:switchTextAppearance
TextAppearance style for text displayed on the switch thumb.
android:textOff
Text to use when the switch is in the unchecked/"off" state.
android:textOn
Text to use when the switch is in the checked/"on" state.
android:textStyle
Style (normal, bold, italic, bold|italic) for the text.
android:thumb
Drawable to use as the "thumb" that switches back and forth.
android:thumbTextPadding
Amount of padding on either side of text within the switch thumb.
android:thumbTint
Tint to apply to the thumb.
android:thumbTintMode
Blending mode used to apply the thumb tint.
android:track
Drawable to use as the "track" that the switch thumb slides within.
android:trackTint
Tint to apply to the track.
android:trackTintMode
Blending mode used to apply the track tint.
android:typeface
Typeface (normal, sans, serif, monospace) for the text.
3、DatePicker
android:calendarTextColor
The text color list of the calendar.
android:calendarViewShown
Whether the calendar view is shown.
android:datePickerMode
Defines the look of the widget.
android:dayOfWeekBackground
The background color for the header's day of week.
android:dayOfWeekTextAppearance
The text color for the header's day of week.
android:endYear
The last year (inclusive), for example "".
android:firstDayOfWeek
The first day of week according to Calendar.
android:headerBackground
The background for the selected date header.
android:headerDayOfMonthTextAppearance
The text appearance for the day of month (ex.
android:headerMonthTextAppearance
The text appearance for the month (ex.
android:headerYearTextAppearance
The text appearance for the year (ex.
android:maxDate
The maximal date shown by this calendar view in mm/dd/yyyy format.
android:minDate
The minimal date shown by this calendar view in mm/dd/yyyy format.
android:spinnersShown
Whether the spinners are shown.
android:startYear
The first year (inclusive), for example "".
android:yearListItemTextAppearance
The list year's text appearance in the list.
android:yearListSelectorColor
The list year's selected circle color in the list.
五、补充
一般来讲,有什么属性,就有对应的set和get方法;另外对代码中的if语句块作个简单说明:它表示android版本大于等于8.0以上才执行if里的内容