当前位置: 首页 > news >正文

重庆市住房和城乡建设部网站做分销网站

重庆市住房和城乡建设部网站,做分销网站,甘肃网络营销是什么,阿里云建站视频教程一、功能介绍 该项目实现的功能主要有#xff1a; 在首页显示一个按钮点击该按钮跳转到桃园页面在桃园页面#xff0c;点击桃子会弹窗显示摘到几个桃子#xff0c;同时被点击桃子消失#xff0c;总桃子数1点击退出桃园会返回首页#xff0c;首页桃子数会根据点击的桃子数…一、功能介绍 该项目实现的功能主要有 在首页显示一个按钮点击该按钮跳转到桃园页面在桃园页面点击桃子会弹窗显示摘到几个桃子同时被点击桃子消失总桃子数1点击退出桃园会返回首页首页桃子数会根据点击的桃子数动态增加 二、代码实现 1. 资源准备 将项目所需要的图片bg.png、monkey.png、btn_peach.png、peach_pic.png 导入程序的drawablehdpi文件夹中默认情况下程序中没有drawable-hdpi 文件夹需手动在res 文件夹中创建一个。 2. 布局文件设计 2.1 主Activity 在layout文件夹中编辑activity_main.xml ?xml version1.0 encodingutf-8? LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationverticalTextViewandroid:layout_widthmatch_parentandroid:layout_height50dpandroid:background#008577android:gravitycenterandroid:text首页android:textColorandroid:color/whiteandroid:textSize20sp /RelativeLayoutandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:backgrounddrawable/bgandroid:gravitycenter_verticalImageViewandroid:idid/iv_monkeyandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:srcdrawable/monkey /Buttonandroid:idid/btn_peachandroid:layout_width80dpandroid:layout_height40dpandroid:layout_marginLeft30dpandroid:layout_marginTop250dpandroid:layout_toRightOfid/iv_monkeyandroid:backgrounddrawable/btn_peachandroid:gravitycenterandroid:text去桃园android:textColorandroid:color/blackandroid:textSize18sp /ImageViewandroid:idid/iv_peachandroid:layout_width45dpandroid:layout_height35dpandroid:layout_belowid/btn_peachandroid:layout_centerHorizontaltrueandroid:layout_marginTop20dpandroid:srcdrawable/peach_pic /TextViewandroid:idid/tv_countandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_belowid/btn_peachandroid:layout_marginTop25dpandroid:layout_marginLeft10dpandroid:layout_toRightOfid/iv_peachandroid:text摘到0 个android:textColorandroid:color/blackandroid:textSize20sp //RelativeLayout /LinearLayout2.2 辅Activity 在layout文件夹中新增activity_peach.xml ?xml version1.0 encodingutf-8? LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationverticalTextViewandroid:layout_widthmatch_parentandroid:layout_height50dpandroid:background#008577android:gravitycenterandroid:text桃园android:textColorandroid:color/whiteandroid:textSize20sp /RelativeLayoutandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:backgrounddrawable/tree_bgRelativeLayoutandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_centerInParenttrueandroid:layout_marginTop70dpandroid:backgrounddrawable/treeButtonandroid:idid/btn_oneandroid:layout_width55dpandroid:layout_height40dpandroid:layout_marginLeft140dpandroid:layout_marginTop35dpandroid:backgrounddrawable/peach_pic /Buttonandroid:idid/btn_twoandroid:layout_width55dpandroid:layout_height40dpandroid:layout_belowid/btn_oneandroid:layout_marginLeft80dpandroid:layout_marginTop5dpandroid:backgrounddrawable/peach_pic /Buttonandroid:idid/btn_threeandroid:layout_width55dpandroid:layout_height40dpandroid:layout_belowid/btn_oneandroid:layout_marginLeft70dpandroid:layout_marginTop5dpandroid:layout_toRightOfid/btn_twoandroid:backgrounddrawable/peach_pic /Buttonandroid:idid/btn_fourandroid:layout_width55dpandroid:layout_height40dpandroid:layout_belowid/btn_twoandroid:layout_marginLeft25dpandroid:layout_marginTop15dpandroid:backgrounddrawable/peach_pic /Buttonandroid:idid/btn_fiveandroid:layout_width55dpandroid:layout_height40dpandroid:layout_belowid/btn_twoandroid:layout_marginLeft70dpandroid:layout_marginTop15dpandroid:layout_toRightOfid/btn_fourandroid:backgrounddrawable/peach_pic /Buttonandroid:idid/btn_sixandroid:layout_width55dpandroid:layout_height40dpandroid:layout_belowid/btn_twoandroid:layout_marginLeft45dpandroid:layout_marginTop15dpandroid:layout_toRightOfid/btn_fiveandroid:backgrounddrawable/peach_pic //RelativeLayoutButtonandroid:idid/btn_exitandroid:layout_width100dpandroid:layout_height40dpandroid:layout_alignParentRighttrueandroid:layout_alignParentBottomtrueandroid:layout_margin50dpandroid:backgrounddrawable/btn_peachandroid:text退出桃园android:gravitycenterandroid:textColorandroid:color/blackandroid:textSize18sp//RelativeLayout /LinearLayout2.3 其他资源文件 主题文件themes.xml resources xmlns:toolshttp://schemas.android.com/tools!-- Base application theme. --style nameTheme.PickPeach parentTheme.MaterialComponents.DayNight.DarkActionBar.Bridge!-- Primary brand color. --item namecolorPrimarycolor/colorPrimary/itemitem namecolorPrimaryVariantcolor/colorPrimaryDark/itemitem namecolorOnPrimarycolor/white/item!-- Secondary brand color. --item namecolorSecondarycolor/teal_200/itemitem namecolorSecondaryVariantcolor/teal_700/itemitem namecolorOnSecondarycolor/black/item!-- Status bar color. --item nameandroid:statusBarColor tools:targetApil?attr/colorPrimaryVariant/item!-- Customize your theme here. --/stylestyle nameMyCustomTheme parentTheme.AppCompat.Light.NoActionBar!-- Primary brand color. --item namecolorPrimarycolor/colorPrimary/itemitem namecolorPrimaryVariantcolor/colorPrimaryDark/itemitem namecolorOnPrimarycolor/white/item!-- Secondary brand color. --item namecolorSecondarycolor/teal_200/itemitem namecolorSecondaryVariantcolor/teal_700/itemitem namecolorOnSecondarycolor/black/item!-- Status bar color. --item nameandroid:statusBarColor tools:targetApil?attr/colorPrimaryVariant/item!-- Customize your theme here. --/style /resources3. 实现逻辑功能 3.0 全局配置文件 ?xml version1.0 encodingutf-8? manifest xmlns:androidhttp://schemas.android.com/apk/res/androidpackagecom.hzj.pickpeachapplicationandroid:allowBackuptrueandroid:iconmipmap/ic_launcherandroid:labelstring/app_nameandroid:roundIconmipmap/ic_launcher_roundandroid:supportsRtltrueandroid:themestyle/MyCustomThemeactivityandroid:name.MainActivityandroid:exportedtrueintent-filteraction android:nameandroid.intent.action.MAIN /category android:nameandroid.intent.category.LAUNCHER //intent-filter/activityactivityandroid:name.PeachActivityandroid:exportedtrue/activity/application/manifest3.1 首页功能 在MainActivity 中实现“去桃园”按钮的点击事件当点击按钮时程序跳转到桃园摘桃的界面。同时还需要接收桃园界面回传过来的桃子个数。 public class MainActivity extends AppCompatActivity {private Button btn_peach;private TextView tv_count;private int totalCount 0;Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);init();}private void init() {btn_peach findViewById(R.id.btn_peach);tv_count findViewById(R.id.tv_count);//为按钮设置点击事件监听器btn_peach.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View view) {//设置意图对象实现界面跳转Intent intent new Intent(MainActivity.this, PeachActivity.class);startActivityForResult(intent, 1); // startActivity(intent);}});}Overrideprotected void onActivityResult(int requestCode, int resultCode, Nullable Intent data) {super.onActivityResult(requestCode, resultCode, data);//判断请求码和返回码是否正确if (requestCode1 requestCode1) {//获取回传的数据int count data.getIntExtra(count, 0);;totalCount totalCount count;tv_count.setText(摘到 totalCount 个);}} }3.2 桃园界面的摘桃效果 点击桃子实现摘桃效果同时全局桃子数动态变化点击退出桃园返回首页同时更新首页桃子数。 public class PeachActivity extends AppCompatActivity implements View.OnClickListener {private Button btn_one, btn_two, btn_three, btn_four, btn_five, btn_six, btn_exit;private int count 0;//桃子个数Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_peach);init();}private void init() {btn_one findViewById(R.id.btn_one);btn_two findViewById(R.id.btn_two);btn_three findViewById(R.id.btn_three);btn_four findViewById(R.id.btn_four);btn_five findViewById(R.id.btn_five);btn_six findViewById(R.id.btn_six);btn_exit findViewById(R.id.btn_exit);btn_one.setOnClickListener(this);btn_two.setOnClickListener(this);btn_three.setOnClickListener(this);btn_four.setOnClickListener(this);btn_five.setOnClickListener(this);btn_six.setOnClickListener(this);btn_exit.setOnClickListener(this);}Overridepublic void onClick(View view) {switch (view.getId()) {case R.id.btn_one: //第一个桃子的点击事件info(btn_one);break;case R.id.btn_two: //第二个桃子的点击事件info(btn_two);break;case R.id.btn_three: //第三个桃子的点击事件info(btn_three);break;case R.id.btn_four: //第四个桃子的点击事件info(btn_four);break;case R.id.btn_five: //第五个桃子的点击事件info(btn_five);break;case R.id.btn_six: //第六个桃子的点击事件info(btn_six);break;case R.id.btn_exit: //“退出桃园”按钮的点击事件returnData();break;default:throw new IllegalStateException(Unexpected value: view.getId());}}/*** 按钮的点击事件处理*/private void info(Button btn) {//桃子个数加1count;//被摘掉的桃子设置为隐藏不可见btn.setVisibility(View.INVISIBLE);Toast.makeText(PeachActivity.this, 摘到 count 个桃子,Toast.LENGTH_LONG).show();}/*** 将数据回传到上个界面*/private void returnData() {//设置意图对象将摘桃子的个数回传给首页界面Intent intent new Intent();intent.putExtra(count, count);//返回码标识setResult(1, intent);//销毁本界面PeachActivity.this.finish();}Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {//当点击设备返回键时调用数据回传方法返回首页界面if (keyCode KeyEvent.KEYCODE_BACK event.getRepeatCount() 0) {returnData();}return false;} }三、效果展示
http://www.pierceye.com/news/307952/

相关文章:

  • 广州企业网站营销电话公司网站怎么做啊
  • 如何利用视频网站做推广网站开发管理学什么
  • 福建漳发建设有限公司网站做网站申请什么商标
  • 专门做房产的网站上海网站开发毕业生
  • 网站域名已经解析但没有被百度等搜索引擎收录怎么办可以做投票功能的网站
  • 重庆网站设计总部什么是社交电商平台
  • 内容管理网站百度电商平台
  • 网站建设 万网网站统计插件
  • 怎么个人网站设计网站建设 不违背
  • 图片下载网站郑州联通网站备案
  • 名师工作室网站建设 意义o2o新零售系统
  • 域名查询权威网站网页设计基础填空题及答案
  • 网站建设策划方案如何写新开传奇新服网
  • dedecms网站上传服务器不是空间网站正则表达式怎么做
  • 青岛企业建设网站企业南宁网站开发建设
  • 网站备案是先做网站还是做完了备案效果好的手机网站建设
  • 做企业宣传网站沈阳妇科检查去哪个医院较好
  • 网站为什么维护wordpress 交易平台
  • 南京 电子商务网站5118数据分析平台官网
  • 试析企业网站建设模式建网站的网络公司
  • 内蒙古建设 招聘信息网站平台搭建
  • 做网站公司共有几处密码公司seo营销
  • 镇江网站制作费用广东华电建设股份有限公司网站
  • 西安知名的集团门户网站建设服务商潍坊网站开发asp培训
  • 网站服务器连接被重置为什么高德地图没有外国位置信息
  • 帝国cms 仿站 wordpress天津新亚太工程建设监理有限公司网站
  • 精品网站导航 做最好的导航网站建设数据库选择
  • 蓝杉网站建设公司贵阳网站建设公司排名
  • 苏州专业高端网站建设机构建网站公司下载快手
  • 中堂仿做网站个人网站设计论文道客巴巴