安卓调用系统日历控件
来源:互联网 发布:mac出现五国 升级 编辑:程序博客网 时间:2024/06/04 23:28
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:background="@android:color/holo_orange_dark" android:layout_width="match_parent" android:layout_height="55dp"> <Button android:onClick="cancel" android:text="取消" android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent"/> <Button android:onClick="confirm" android:text="确认" android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent"/> </LinearLayout> <DatePicker android:id="@+id/datepicker" android:layout_width="match_parent" android:calendarViewShown="false" android:layout_height="wrap_content"/></LinearLayout>
public class MainActivity extends AppCompatActivity { private DatePicker datePicker; private int year; private int month;//月份是从0开始算的. private int day; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏 setContentView(R.layout.activity_main); datePicker = (DatePicker) findViewById(R.id.datepicker);// initData(); } public void initData(){ Calendar calendar = Calendar.getInstance(); year = calendar.get(Calendar.YEAR); month = calendar.get(Calendar.MONTH); day = calendar.get(Calendar.DAY_OF_MONTH); datePicker.init(year, month, day, new DatePicker.OnDateChangedListener() { @Override public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Toast.makeText(MainActivity.this, year + "年" + (monthOfYear+1) + "月" + dayOfMonth + "日", Toast.LENGTH_SHORT).show(); } }); } public void cancel(View v){ Toast.makeText(this, "取消,按照工单给的补抄日期", Toast.LENGTH_SHORT).show(); } public void confirm(View v){ Toast.makeText(this, "确认", Toast.LENGTH_SHORT).show(); }}
备注:
1.这里必须继承AppCompatActivity,才会出现这个界面,否则你继承的是Activity,出现的界面很丑,黑白的,但是你有时候继承
AppCompatActivity会报错.
报错如下:java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test2/com.example.test2.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.解决方法:创建的activity是MainActivity extends ActionBarActivity这样的。把后面的ActionBarActivity改成Activity,然后导包,把下面报错的地方删掉运行就不报错了。。。导入support:appcompat-v7支持包,我导入的25.1版本的.另外导入的时候也可能报错,需要修改compileSdkVersion版本.compile 'com.android.support:appcompat-v7:25.1.0'
阅读全文
0 0
- 安卓调用系统日历控件
- 安卓自定义日历控件
- 安卓自定义日历控件
- 安卓自定义日历滑动的日历控件
- android 调用系统日历
- iOS调用系统日历
- 安卓Andriod使用入门(七)【Android日历控件】
- layDate日历控件的调用
- 安卓日历
- 安卓日历
- Android实现调用系统日历
- 安卓系统控件继承树
- Android 调用系统闹钟和系统日历
- 安卓、苹果日历同步
- 安卓自定义日历选择器
- 安卓自定义日历选择器
- 安卓调用系统下载功能
- 安卓调用系统分享功能
- 45-数字调换
- (Kotlin1)初识Kotlin编程语言
- eclipse视图下看不到classes目录
- centos7如何添加开机启动服务/脚本
- STM32-新建工程
- 安卓调用系统日历控件
- Spring统一异常处理
- log4j与log4j2的配合使用、slf4j
- LeetCode 220. Contains Duplicate III *****理解条件,查找表
- 隐马尔科夫模型、三个基本问题、三个训练算法
- 如何向销售(业余人士)解释TINA系统
- Java线程基础
- Tomcat服务器的问题
- 谈谈构建高性能WEB之HTTP首部优化