安卓Andriod使用入门(十七)【卡片视图的形式管理Activity】
来源:互联网 发布:人工智能丛书 编辑:程序博客网 时间:2024/04/30 06:33
人生最终的价值在于觉悟和思考的能力,而不只是在于生存。——亚里士多德
MainActivity.java代码:
package siso.aswitcher;import android.app.Activity;import android.app.Application;import android.content.Intent;import android.graphics.Color;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.MotionEvent;import android.view.View;import android.widget.Button;import android.widget.RelativeLayout;import android.widget.TextView;import siso.aslibrary.ActivitySwitcher;public class MainActivity extends AppCompatActivity { static int index; static int totalCount = 8; static int[] bgColors = new int[] { Color.parseColor("#92c8d0"), Color.parseColor("#c4dcce"), Color.parseColor("#cd7b91"), Color.parseColor("#e5c5dc"), Color.parseColor("#742a8d"), Color.parseColor("#2eb2d8"), Color.parseColor("#b9d84e"), Color.parseColor("#35fe62") }; private RelativeLayout relativeLayout; private Button btnNext; private TextView tvPage; private ActivitySwitcher activitySwitcher; private int tag; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); activitySwitcher = ActivitySwitcher.getInstance(); relativeLayout = (RelativeLayout) findViewById(R.id.relayout); btnNext = (Button) findViewById(R.id.btn_next); tvPage = (TextView) findViewById(R.id.tv_page); relativeLayout.setBackgroundColor(bgColors[index]); tag = index; tvPage.setText("当前第" + (tag + 1) + "页" ); if (index == totalCount - 1) { btnNext.setText("退出程序"); } btnNext.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (++index > totalCount - 1) { activitySwitcher.exit(); } else { startActivity(new Intent(MainActivity.this, MainActivity.class)); } } }); activitySwitcher.setOnActivitySwitchListener(new ActivitySwitcher.OnActivitySwitchListener() { @Override public void onSwitchStarted() {} @Override public void onSwitchFinished(Activity activity) { if (activity instanceof MainActivity) { MainActivity mainActivity = (MainActivity) activity; MainActivity.index = mainActivity.getTag(); } } }); } @Override public boolean dispatchTouchEvent(MotionEvent ev) { activitySwitcher.processTouchEvent(ev); return super.dispatchTouchEvent(ev); } @Override public void onBackPressed() { MainActivity.index = tag - 1 <= 0 ? 0 : tag - 1; activitySwitcher.finishSwitch(this); } public int getTag() { return tag; }}
MyApplication.java代码:
package siso.aswitcher;import android.app.Application;import siso.aslibrary.ActivitySwitcher;public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); ActivitySwitcher.getInstance().init(this); }}
AndroidManifest.xml内容:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="siso.aswitcher"> <application android:name=".MyApplication" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>
Andriod 库项目结构:
项目运行结果如图:
0 0
- 安卓Andriod使用入门(十七)【卡片视图的形式管理Activity】
- 安卓Andriod使用入门(二十七)【点赞动画】
- 卡卡片视图的形式管理你的 Activity,让你的 app 可以自由的切换、跳转、关闭 Activity 以及结束 app 程序
- 安卓Andriod使用入门(一)【圆形Menu菜单】
- 安卓Andriod使用入门(二)【高仿安卓微信6.0】
- 安卓Andriod使用入门(三)【2048游戏】
- 安卓Andriod使用入门(四)【图片毛玻璃效果】
- 安卓Andriod使用入门(五)【分类侧滑菜单】
- 安卓Andriod使用入门(六)【动态GridView控件】
- 安卓Andriod使用入门(七)【Android日历控件】
- 安卓Andriod使用入门(八)【联动ListView】
- 安卓Andriod使用入门(九)【悬浮窗菜单】
- 安卓Andriod使用入门(十一)【下拉刷新】
- 安卓Andriod使用入门(十二)【网络爬虫】
- 安卓Andriod使用入门(十四)【滑动布局】
- 安卓Andriod使用入门(十九)【视频播放列表】
- 安卓Andriod使用入门(二十)【颜色对话框】
- 安卓Andriod使用入门(二十三)【百度地图API】
- 各大排序算法的总结
- 在eclipse中对已存在的类重命名
- 正则表达式基本语法
- 加密简介
- 解析Spark开源框架elephas之一
- 安卓Andriod使用入门(十七)【卡片视图的形式管理Activity】
- 现代通用编程语言简介
- 单例
- 如何通过ip访问MySql数据库
- 初学JDBC(七)-使用CallableStatement接口调用存储过程
- 免安装版tomcat 配置相关问题 startup闪退
- 安卓Touch事件的分发机制
- Android插件化学习之路(二)之ClassLoader完全解析
- 分布式系统知识罗列