模拟考试
来源:互联网 发布:淘宝客优惠券加人 编辑:程序博客网 时间:2024/04/29 11:58
需求一:使用Android Studio建项目,并通过github进行版本控制。(25分)
1) 使用studio创建一个项目并在github上创建“姓名全拼Project”仓库(5分)
2)使用git命令将项目上传至“姓名全拼Project”仓库(10分)
3) 使用studio clone到本地(5分),完成以下需求后将修改推到远程仓库(5分)
需求二:实现类似效果图TopBar复合型控件效果,如图1(65分)
1) 自定义控件样式实现没问题。(10分)
2) 支持自定义属性,在attrs.xml中配置正确:中间标题内容文字,字体大小,文字颜色,背景颜色(8分)
3) 支持自定义属性,在attrs.xml中配置正确:左边按钮文字,字体大小,文字颜色,背景颜色(8分)
4) 支持自定义属性,在attrs.xml中配置正确:右边按钮文字,字体大小,文字颜色,背景颜色(8分)
5) 构造方法中自定义属性配置正确(5分)
6) 左右按钮通过回调接口定义点击事件。(10分)
7) 点击左右按钮弹出吐司,如图1。(5分)
8) 在布局文件中使用复合型控件时使用自定义的属性赋值(5分)
9) 左右按钮背景设置背景选择器,点击时红色,未点击时蓝色。(6分)
/***************************************************************************************************************
MainActivity/
package com.example.weekonecustomview;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); }}/******************************************************************/TopBarpackage com.example.weekonecustomview;import android.content.Context;import android.content.res.TypedArray;import android.graphics.Color;import android.os.Build;import android.support.annotation.Nullable;import android.util.AttributeSet;import android.view.View;import android.widget.Button;import android.widget.LinearLayout;import android.widget.TextView;import android.widget.Toast;/** * Created by hasee on 2017/9/2. */public class TopBar extends LinearLayout implements View.OnClickListener { private TextView title; private Button leftBtn; private Button rightBtn; public TopBar(Context context) { super(context); initView(context, null); } public TopBar(Context context, @Nullable AttributeSet attrs) { super(context, attrs); initView(context, attrs); } private void initView(Context context, AttributeSet attrs) { View inflate = inflate(context, R.layout.top_bar_layout, this); title = (TextView) inflate.findViewById(R.id.title_tv); leftBtn = (Button) inflate.findViewById(R.id.left_btn); rightBtn = (Button) inflate.findViewById(R.id.right_btn); leftBtn.setOnClickListener(this); rightBtn.setOnClickListener(this); if (attrs == null) { return; } initAttrs(context, attrs); } private void initAttrs(Context context, AttributeSet attrs) { TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TopBar); title.setText(typedArray.getString(R.styleable.TopBar_title_text)); leftBtn.setText(typedArray.getString(R.styleable.TopBar_left_btn_text)); rightBtn.setText(typedArray.getString(R.styleable.TopBar_right_btn_text)); title.setTextColor(typedArray.getColor(R.styleable.TopBar_title_text_color, Color.BLACK)); leftBtn.setTextColor(typedArray.getColor(R.styleable.TopBar_left_btn_text_color, Color.BLACK)); rightBtn.setTextColor(typedArray.getColor(R.styleable.TopBar_right_btn_text_color, Color.BLACK)); title.setTextSize(typedArray.getDimension(R.styleable.TopBar_title_text_size, 16)); leftBtn.setTextSize(typedArray.getDimension(R.styleable.TopBar_left_btn_text_size, 16)); rightBtn.setTextSize(typedArray.getDimension(R.styleable.TopBar_right_btn_text_size, 16)); title.setBackgroundColor(typedArray.getColor(R.styleable.TopBar_title_bg_color, Color.BLUE)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { leftBtn.setBackground(typedArray.getDrawable(R.styleable.TopBar_left_btn_bg_color)); rightBtn.setBackground(typedArray.getDrawable(R.styleable.TopBar_right_btn_bg_color)); }else{ leftBtn.setBackgroundDrawable(typedArray.getDrawable(R.styleable.TopBar_left_btn_bg_color)); rightBtn.setBackgroundDrawable(typedArray.getDrawable(R.styleable.TopBar_right_btn_bg_color)); } } @Override public void onClick(View v) { String content =""; if (v.equals(leftBtn)) { content ="点击左侧按钮"; } else if (v.equals(rightBtn)) { content ="点击右侧按钮"; } Toast.makeText(v.getContext(),content,Toast.LENGTH_LONG).show(); }}
/***************************************************************************************res/color/my_color_selected_dd.xml/<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:color="@color/colorPrimary" android:state_pressed="false"/> <item android:color="@color/colorAccent" android:state_pressed="true" /></selector>/*************************************************************************************drawable/my_color_selected.xml/<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/colorPrimary" android:state_pressed="false"/> <item android:drawable="@color/colorAccent" android:state_pressed="true" /></selector>/**********************************************************************************lyout/activity_main.mal/<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <com.example.weekonecustomview.TopBar app:title_text="这是我的activity" android:layout_width="match_parent" android:layout_height="wrap_content" app:left_btn_bg_color="@drawable/my_clolor_selected" app:left_btn_text="左侧" app:left_btn_text_color="#000000" app:left_btn_text_size="12dp" app:right_btn_bg_color="@drawable/my_clolor_selected" app:right_btn_text="右侧" app:right_btn_text_color="#000000" app:right_btn_text_size="12dp" app:title_bg_color="@color/colorAccent" app:title_text_color="#000000" /> <Button android:textColor="@color/my_clolor_selected_dd" android:background="@drawable/my_clolor_selected" android:text="处处存储错错" android:layout_width="wrap_content" android:layout_height="wrap_content" /></LinearLayout>/********************************************************layout/top_bar_layout.mal/<?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="80dp" android:orientation="horizontal"> <Button android:id="@+id/left_btn" android:layout_width="80dp" android:layout_height="match_parent" /> <TextView android:id="@+id/title_tv" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="标题" /> <Button android:id="@+id/right_btn" android:layout_width="80dp" android:layout_height="match_parent" /></LinearLayout>/****************************************************************8values/attrs.mal/<?xml version="1.0" encoding="utf-8"?><resources> <declare-styleable name="TopBar"> <attr name="title_text" format="string"></attr> <attr name="title_text_size" format="dimension"></attr> <attr name="title_text_color" format="color"></attr> <attr name="title_bg_color" format="color"></attr> <attr name="left_btn_text" format="string"></attr> <attr name="left_btn_text_size" format="dimension"></attr> <attr name="left_btn_text_color" format="color"></attr> <attr name="left_btn_bg_color" format="reference"></attr> <attr name="right_btn_text" format="string"></attr> <attr name="right_btn_text_size" format="dimension"></attr> <attr name="right_btn_text_color" format="color"></attr> <attr name="right_btn_bg_color" format="reference"></attr> </declare-styleable></resources>
阅读全文
0 0
- 模拟考试
- NOIP模拟考试
- 驾照模拟考试所得。
- 新四六级模拟考试
- NOIP2011模拟考试总结
- NOIP2009模拟考试总结
- COCI模拟考试心得体会
- 省选模拟考试1
- 2016.12.03模拟考试总结
- 实现模拟考试的答案
- 系分在线模拟考试
- 关于模拟考试网站
- 1109 NOIP 模拟考试
- 16.1112 模拟考试 T1
- 16.1113 模拟考试T3
- 16.1113 模拟考试T1
- 16.1113 模拟考试T2
- 16.1114 模拟考试T1
- SpringMVC 拦截器不拦截静态资源的三种处理方式
- 超励志:82岁日本老太自学编程获库克接见
- 机械革命安装OSD
- C++中this指针的理解和用法
- Java并发编程系列之二十五:线程池
- 模拟考试
- 30 多年的编码经验浓缩成的 10 条最佳实践
- 2017.9.3
- c#学Java
- 《程序员的自我修养--链接、装载与库》笔记--第一章温故而知新
- 漏洞银行/逆向工程学习日记(3)-内存寻址方式
- Java并发包源码学习之线程池(一)ThreadPoolExecutor源码分析
- C++通过cin.get()输入字符串
- 使用树莓派3B开启WIFI热点