智能终端APP程序开发 自定义控件的使用 作业6.doc

智能终端APP程序开发 自定义控件的使用 作业6.doc

  1. 1、本文档共5页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
请完成以下实践题目,将结果截图放在题目后面即可。 为APP程序定义标题栏并实现功能 很多程序最上方都有一个标题栏,这个标题栏显然是跨界面的,在不同的Activity中作用一直,基本包括后退和前进按钮以及标题。 像这样大量复用的情况,如果每一页都要把对应代码重复以便会造成大量冗余,因此我们把这个标题栏单独拿出来定义,使得每一个Layout都可以对标题栏所属的Layout做相应的引用。 要求实现结果如下图: 可以参考如下解题过程 首先,新建一个程序,过程不再赘述,结果如下。 在现有的基础上,在Layout文件夹下定义一个新的布局文件,作为标题栏的布局文件,很明显是是一个横向的线性布局,代码如下。 ?xml version=1.0 encoding=utf-8? LinearLayout xmlns:android=/apk/res/android android:layout_width=match_parent android:layout_height=match_parent android:orientation=horizontal Button android:id=@+id/btn_back android:layout_width=wrap_content android:layout_height=wrap_content android:text=返回 / TextView android:layout_width=wrap_content android:layout_height=wrap_content android:layout_weight=1 android:gravity=center android:text=这个是标题 / Button android:id=@+id/btn_next android:layout_width=wrap_content android:layout_height=wrap_content android:text=下一个 / /LinearLayout 然后将新添加的布局添加到与当前运行的Activity相关联的Layout中,代码如下图标红部分。 ?xml version=1.0 encoding=utf-8? android.support.constraint.ConstraintLayout xmlns:android=/apk/res/android xmlns:app=/apk/res-auto xmlns:tools=/tools android:layout_width=match_parent android:layout_height=match_parent tools:context=.MainActivity include layout=@layout/layout/ TextView android:layout_width=wrap_content android:layout_height=wrap_content android:text=Hello World! app:layout_constraintBottom_toBottomOf=parent app:layout_constraintLeft_toLeftOf=parent app:layout_constraintRight_toRightOf=parent app:layout_constraintTop_toTopOf=parent / /android.support.constraint.ConstraintLayout 运行结果如下: 下面我们在程序逻辑文件SRC的当前JAVA包中新建一个class用来实现标题栏的功能,代码如下【别忘记给刚才的标题栏TextView加个id】: package com.example.myapplication; import android.content.Context; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.wi

文档评论(0)

WanDocx + 关注
实名认证
内容提供者

大部分文档都有全套资料,如需打包优惠下载,请留言联系。 所有资料均来源于互联网公开下载资源,如有侵权,请联系管理员及时删除。

1亿VIP精品文档

相关文档