对于想了解css–KendoDatepicker:改变其内部的大小或字体的读者,本文将是一篇不可错过的文章,我们将详细介绍csscheckbox样式修改,并且为您提供关于AndroidCalendar
对于想了解css – Kendo Datepicker:改变其内部的大小或字体的读者,本文将是一篇不可错过的文章,我们将详细介绍csscheckbox样式修改,并且为您提供关于Android CalendarView,DatePicker,TimePicker,以及NumberPicker的使用、Android DatePicker和DatePickerDialog基本用法示例、Android DatePicker和TimePicker:时间日期选择器、android – 如何从DatePickerDialog获取DatePicker?的有价值信息。
本文目录一览:- css – Kendo Datepicker:改变其内部的大小或字体(csscheckbox样式修改)
- Android CalendarView,DatePicker,TimePicker,以及NumberPicker的使用
- Android DatePicker和DatePickerDialog基本用法示例
- Android DatePicker和TimePicker:时间日期选择器
- android – 如何从DatePickerDialog获取DatePicker?
css – Kendo Datepicker:改变其内部的大小或字体(csscheckbox样式修改)
Datepicker以某种方式膨胀,比通常的字体和大小更大.在Kendo窗口之外,日期选择器显示正常.现在,我想知道我是否可以调整日期选择器或其中的字体,假设缩小字体也会缩小日期选择器的大小.
我试过把它添加到CSS中:
.k-popup .k-calendar { font-size: 10px !important; }
结果很奇怪:
它只是部分工作,因为只有月份名称减少,数字仍然很大……
主要问题是,当打开日期选择器时,它会溢出kendo窗口维度:我正在寻找一种解决方案,允许我缩小日期选择器的尺寸以使其适合.
编辑
我试着添加k-calendar类:
@(Html.Kendo().DatePicker() .Name("concessionTOD") .Start(CalendarView.Month) .Value(DateTime.Now) .Format("yyyy-MM-dd") .Culture("pt-PT") .HtmlAttributes(new { @}) )
但结果如下:
你可以在上面的图片中看到输入和月份名称的大小确实减少了,但是日历本身保持臃肿.
编辑2
我了解到,如果窗口被定义为iFrame,内部结果可能会有所不同,因为iFrame作为常规网页需要DOCTYPE以及html,head和body标签.我将此添加到插入窗口的部分视图中,结果如下:
因此,日历不再膨胀,但仍然溢出窗口的高度,导致滚动条出现.要访问日历的下半部分,我必须使用滚动.如前所述,我希望日历在窗口外溢出,如OnaBai的回答所示,而不创建任何滚动条.
另外,我在documentation发现了
从远程URL或最初定义的内容模板刷新Window的内容.请注意,传递数据和非GET请求无法发送到iframe,因为它们需要具有target属性的表单.
我不确定如何解释第二句,但它可能有助于处理这个问题.
解决方法
.k-calendar { font-size: 10px; }
请检查以下代码段.
$("#datepicker").kendoDatePicker(); $("#win").kendoWindow({ title: "window with datepicker" });
.k-calendar { font-size: 10px; }
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.common.min.css" /> <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.default.min.css" /> <script src="http://cdn.kendostatic.com/2014.3.1119/js/jquery.min.js"></script> <script src="http://cdn.kendostatic.com/2014.3.1119/js/kendo.all.min.js"></script> <div id="win"> <input id="datepicker" value="10/10/2011"/> </div>
Android CalendarView,DatePicker,TimePicker,以及NumberPicker的使用
Android CalendarView,DatePicker,TimePicker,以及NumberPicker的使用
简单复习下基础UI组件,做个简单的总结,Android的这些组件封装的特别好,基本套上就能使用,当然,这个减轻了开发者的负担!不过如果想要深入研究,这里面还是有很大的空间值得深度分析!简单的几个例子!仅供参考:
不多说,先上效果图:
CalendarView
ChooseView
NumberPicker
CalendarView代码区 :
main.xml代码区:CalendarView组件的使用加上一些简单的属性即可!
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="选择您的生日:"/> <!-- 设置以星期二作为每周第一天 设置该组件总共显示4个星期 并对该组件的日期时间进行了定制 --> <CalendarView android:layout_width="match_parent" android:layout_height="match_parent" android:firstDayOfWeek="3" android:shownWeekCount="4" android:selectedWeekBackgroundColor="#aff" android:focusedMonthDateColor="#f00" android:weekSeparatorLineColor="#ff0" android:unfocusedMonthDateColor="#f9f" android:id="@+id/calendarView" /> </LinearLayout>
Activity区代码:
public class MainActivity extends Activity { CalendarView cv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); cv = (CalendarView)findViewById(R.id.calendarView); // 为CalendarView组件的日期改变事件添加事件监听器 cv.setonDatechangelistener(new OnDatechangelistener() { @Override public void onSelectedDayChange(CalendarView view,int year,int month,int dayOfMonth) { // 使用Toast显示用户选择的日期 Toast.makeText(MainActivity.this,"你生日是" + year + "年" + month + "月" + dayOfMonth + "日",Toast.LENGTH_SHORT).show(); } }); } }
DatePicker,结合Calerdar的使用,可以供用户选择日期时使用:
代码区:
main.xml代码:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="选择购买本书的具体时间"/> <!-- 定义一个DatePicker组件 --> <DatePicker android:id="@+id/datePicker" android:layout_width="wrap_content" android:layout_height="200dp" android:layout_gravity="center_horizontal" android:startYear="2000" android:endYear="2016" android:calendarViewShown="true" android:spinneRSShown="true"/> <!-- 定义一个TimePicker组件 --> <TimePicker android:id="@+id/timePicker" android:layout_width="wrap_content" android:layout_height="100dp" android:layout_gravity="center_horizontal"/> <!-- 显示用户输入日期、时间的控件 --> <EditText android:id="@+id/show" android:layout_width="match_parent" android:layout_height="wrap_content" android:editable="false" android:cursorVisible="false"/> </LinearLayout>
Activity代码:
public class MainActivity extends Activity { // 定义5个记录当前时间的变量 private int year; private int month; private int day; private int hour; private int minute; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); DatePicker datePicker = (DatePicker) findViewById(R.id.datePicker); TimePicker timePicker = (TimePicker) findViewById(R.id.timePicker); // 获取当前的年、月、日、小时、分钟 Calendar c = Calendar.getInstance(); year = c.get(Calendar.YEAR); month = c.get(Calendar.MONTH); day = c.get(Calendar.DAY_OF_MONTH); hour = c.get(Calendar.HOUR); minute = c.get(Calendar.MINUTE); // 初始化DatePicker组件,初始化时指定监听器 datePicker.init(year,month,day,new OnDateChangedListener() { @Override public void onDateChanged(DatePicker arg0,int day) { MainActivity.this.year = year; MainActivity.this.month = month; MainActivity.this.day = day; // 显示当前日期、时间 showDate(year,hour,minute); } }); timePicker.setEnabled(true); // 为TimePicker指定监听器 timePicker.setonTimeChangedListener(new OnTimeChangedListener() { @Override public void onTimeChanged(TimePicker view,int hourOfDay,int minute) { MainActivity.this.hour = hourOfDay; MainActivity.this.minute = minute; // 显示当前日期、时间 showDate(year,minute); } }); } // 定义在EditText中显示当前日期、时间的方法 private void showDate(int year,int day,int hour,int minute) { EditText show = (EditText) findViewById(R.id.show); show.setText("您的购买日期为:" + year + "年" + (month + 1) + "月" + day + "日 " + hour + "时" + minute + "分"); } }
NumberPicker主要使用在给用户提供数字选择时使用。
main.xml代码:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:text="选择低价:" android:layout_width="120dp" android:layout_height="wrap_content" /> <NumberPicker android:id="@+id/np1" android:layout_width="match_parent" android:layout_height="80dp" android:focusable="true" android:focusableInTouchMode="true" /> </TableRow> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:text="选择高价:" android:layout_width="120dp" android:layout_height="wrap_content" /> <NumberPicker android:id="@+id/np2" android:layout_width="match_parent" android:layout_height="80dp" android:focusable="true" android:focusableInTouchMode="true" /> </TableRow> </TableLayout>
Activity代码:
public class MainActivity extends Activity { NumberPicker np1,np2; // 定义最低价格、最高价格的初始值 int minPrice = 25,maxPrice = 75; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); np1 = (NumberPicker) findViewById(R.id.np1); // 设置np1的最小值和最大值 np1.setMinValue(10); np1.setMaxValue(50); // 设置np1的当前值 np1.setValue(minPrice); np1.setonValueChangedListener(new OnValuechangelistener() { // 当NumberPicker的值发生改变时,将会激发该方法 @Override public void onValueChange(NumberPicker picker,int oldVal,int newVal) { minPrice = newVal; showSelectedPrice(); } }); np2 = (NumberPicker) findViewById(R.id.np2); // 设置np2的最小值和最大值 np2.setMinValue(60); np2.setMaxValue(100); // 设置np2的当前值 np2.setValue(maxPrice); np2.setonValueChangedListener(new OnValuechangelistener() { // 当NumberPicker的值发生改变时,将会激发该方法 @Override public void onValueChange(NumberPicker picker,int newVal) { maxPrice = newVal; showSelectedPrice(); } }); } private void showSelectedPrice() { Toast.makeText(this,"您选择最低价格为:" + minPrice + ",最高价格为:" + maxPrice,Toast.LENGTH_SHORT) .show(); } }
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
Android DatePicker和DatePickerDialog基本用法示例
本文实例讲述了Android DatePicker和DatePickerDialog基本用法。分享给大家供大家参考,具体如下:
DatePicker用来设置手机的时间和闹钟
1、添加一个按钮控件在配置文件中,然后给该按钮添加事件,使其能够打开DatePicker
//下面采用匿名内部类的方式 btn.setonClickListener(new Button.OnClickListener(){ @Override public void onClick(View v) { //通过下面的方法可以调用回调函数onCreateDialog()方法,其中参数传递给onCreateDialog()方法 //一定要用onCreateDialog()方法,因为它的返回值为Dialog对象 showDialog(DATE_DIALOG_ID); } });
2、使用了showDialog方法之后就会调用回调函数onCreateDialog()方法,通过该方法打开以对话框形式弹出的时间设置器
@Override protected Dialog onCreateDialog(int id) { switch (id) { case DATE_DIALOG_ID: //mDateSetListener这个参数是用来告诉Android设置完时间之后点击set回调函数用的方法 return new DatePickerDialog(this,mDateSetListener,2011,10,25); case TIME_DIALOG_ID: return new TimePickerDialog(this,mTimeSetListener,14,12,true); } return null; }
3、根据DatePickerDialog这个构造方法需要添加一个“监听器”,即用户点击SET按钮之后会处理的方法
//DatePickerDialog设置完之后有的回调函数 public DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() { //下面的参数是用户设置完之后的时间 @Override public void onDateSet(DatePicker view,int year,int monthOfYear,int dayOfMonth) { System.out.println("DatePickerDialog.OnDateSetListener"); dateShowView.setText(new StringBuffer().append(year).append("-").append(monthOfYear).append("-").append(dayOfMonth)); } };
拓展:同样,对时间的设置也类似于这个过程
更多关于Android相关内容感兴趣的读者可查看本站专题:《Android文件操作技巧汇总》、《Android编程开发之SD卡操作方法汇总》、《Android开发入门与进阶教程》、《Android资源操作技巧汇总》、《Android视图View技巧总结》及《Android控件用法总结》
希望本文所述对大家Android程序设计有所帮助。
Android DatePicker和TimePicker:时间日期选择器
Android SDK 提供了 DatePicker 和 TimePicker 组件,分别对日期和时间进行选择,方便日期和时间设定。
下面用一个简单的实例讲解 DatePicker 和 TimePicker 组件的使用方法。在工程 WidgetDemo 的布局文件 main.xml 中添加一个名为“Date/Time”的 Button,用以启动 TimeActivity。
在 main.xml 中添加代码如下:
- <Button
- android:id="@+id/button6"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Date/Time"/>
单击 Button 并启动 TimeActivity 的代码如下:
- Button timebtn = (Button)this.findViewById(R.id.button6);
- timebtn.setonClickListener(new OnClickListener(){
- @Override
- public void onClick(View v){
- Intent intent = new Intent(WidgetDemoActivity.this, TimeActivity.class);
- startActivity(intent);
- }
- });
同时在 AndroidManifest.xml 文件中声明该 Activity:
<activity android:name=" .TimeActivity"></activity>
TimeActivity 的运行效果如图 1 所示。
图 1 TimeActivity的运行效果
TimeActivity 使用的布局文件为 time.xml,其内容如下:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <TextView
- android:id="@+id/timeview"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="DatePicker和TimePicker"/>
- <TimePicker
- android:id="@+id/timepicker"
- android:layout_width="wrap_content"
- android:layout_height="116dp"
- android:background="#778888"/>
- <!--设置背景色为墨绿-->
- <DatePicker
- android:id="@+id/datepicker"
- android:layout_width="271dp"
- android:layout_height="196dp"
- android:background="#778899"/>
- </LinearLayout>
TimeActivity.java 的代码如下:
- package introduction.android.widgetdemo;
- import java.util.Calendar;
- import android.app.Activity;
- import android.os.Bundle;
- import android.widget.DatePicker;
- import android.widget.TextView;
- import android.widget.TimePicker;
- public class TimeActivity extends Activity {
- private TextView textview;
- private TimePicker timepicker;
- private DatePicker datepicker;
- /* 声明日期及时间变量*/
- private int year;
- private int month;
- private int day;
- private int hour;
- private int minute;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.time);
- /*获取当前日期及时间 */
- Calendar calendar = Calendar.getInstance();
- year = calendar.get(Calendar.YEAR);
- month = calendar.get(Calendar.MONTH);
- day = calendar.get(Calendar.DAY_OF_MONTH);
- hour = calendar.get(Calendar.HOUR);
- minute = calendar.get(Calendar.MINUTE);
- datepicker = (DatePicker) findViewById(R.id.datepicker);
- timepicker = (TimePicker) findViewById(R.id.timepicker);
- /* 设置TextView对象,显示初始日期时间 */
- textview = (TextView) findViewById(R.id.timeview);
- textview.setText(new StringBuilder().append(year).append("/")
- .append(format(month + 1)).append("/")
- .append(format(day)).append(" ")
- .append(format(hour)).append(":")
- .append(format(minute)));
- /* 设置OnDateChangedListener()*/
- datepicker.init(year, month, day,
- new DatePicker.OnDateChangedListener() {
- @Override
- public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
- // Todo Auto-generated method stub
- TimeActivity.this.year = year;
- month = monthOfYear;
- day = dayOfMonth;
- textview.setText(new StringBuilder().append(year).
- append("/").append(format(month + 1))
- .append("/").append(format(day)).append(" ")
- .append(format(hour)).append(":")
- .append(format(minute)));
- }
- });
- timepicker.setonTimeChangedListener(new TimePicker.OnTimeChangedListener() {
- @Override
- public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
- // Todo Auto-generated method stub
- hour = hourOfDay;
- TimeActivity.this.minute = minute;
- textview.setText(new StringBuilder().append(year)
- .append("/").append(format(month + 1))
- .append("/").append(format(day)).append(" ")
- .append(format(hour)).append(":")
- .append(format(minute)));
- }
- });
- }
- private String format(int time) {
- String str = "" + time;
- if (str.length() == 1)
- str = "0" + str;
- return str;
- }
- }
TimeActivity 中使用 java.util.Calendar 对象获取当前系统时间。
当更改 DatePicker 组件中的日期时,会触发 DatePicker 的 OnDateChange() 事件;
当修改 TimePacker 的时间时,会触发 TimePacker 的 OnDateChange() 事件。
由本实例可见,DatePicker 实现 OnDateChangedListener 监听器的方法与 TimePicker 实现 setonTimeChangedListener 监听器的方法有所类似。
DatePicker 用 init() 方法设定年、月、日的同时设定监听器,而 TimePicker 使用 setonTimeChangedListener() 直接设定。
android – 如何从DatePickerDialog获取DatePicker?
DatePickerDialog dialog = new DatePickerDialog(this,startDateSetListener,start_cal.get(Calendar.YEAR),start_cal.get(Calendar.MONTH),start_cal.get(Calendar.DATE));
我想从DatePickerDialog中获取DatePicker视图,以便我可以设置最小和最大日期. API参考指出,有一个方法getDatePicker,并且自API 1以来一直存在,但它是无效的,我的ide不喜欢它.
DatePicker picker = dialog.getDatePicker();
“对于DatePickerDialog类型,getDatePicker()方法未定义”
任何人知道API是创建的方法,或者如何获取到DatePicker来编辑最小/最大日期?
我正在使用API 7,Platform 2.1.
解决方法
DatePickerDialog dialog = ... // create dialog Field mDatePickerField = dialog.getClass().getDeclaredField("mDatePicker"); mDatePickerField.setAccessible(true); DatePicker mDatePickerInstance = (DatePicker) mDatePickerField.get(dialog);
从此,您可以引用内部的DatePicker对象,您应该可以根据自己的喜好进行更改.请注意任何明显的错字,因为我直接进入浏览器.
今天关于css – Kendo Datepicker:改变其内部的大小或字体和csscheckbox样式修改的分享就到这里,希望大家有所收获,若想了解更多关于Android CalendarView,DatePicker,TimePicker,以及NumberPicker的使用、Android DatePicker和DatePickerDialog基本用法示例、Android DatePicker和TimePicker:时间日期选择器、android – 如何从DatePickerDialog获取DatePicker?等相关知识,可以在本站进行查询。
本文标签: