首页 / 安卓 / 安卓开发笔记(二十九):顶部导航栏
安卓开发笔记(二十九):顶部导航栏
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了安卓开发笔记(二十九):顶部导航栏,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2374字,纯文字阅读大概需要4分钟。
内容图文
![安卓开发笔记(二十九):顶部导航栏](/upload/InfoBanner/zyjiaocheng/1113/54a1b90487f542a8aa532d9d16b7f792.jpg)
首先上图:
实现这个标题栏,我们还需要一个返回的按钮,这里也贴出来。笔者直接将这个简单的标题栏制作成了一个依赖库,放在到github上,方便下次进行调用。
返回按钮如下:
在使用这个按钮的时候需要注意其尺寸的大小一定要小于我们的标题栏。
view_top.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="#50e7ab" android:padding="10dp"> <ImageView android:id="@+id/top_left" android:layout_width="30dp" android:layout_height="30dp" android:src="@drawable/great2" /> <TextView android:id="@+id/top_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="首页" android:textSize="17sp" android:textColor="#ffffff" /> <TextView android:id="@+id/top_right" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="提交" android:textSize="17sp" android:textColor="#ffffff" android:layout_centerVertical="true" android:layout_alignParentRight="true" /> </RelativeLayout>
新建的topview类:
import android.content.Context; import android.util.AttributeSet; import android.view.LayoutInflater; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; import com.example.lenovo.deeplove2.R; public class TopView extends RelativeLayout { // 返回按钮控件 private ImageView top_left; // 标题Tv private TextView top_title; private TextView top_right; public TopView(Context context) { super(context); } public TopView(Context context, AttributeSet attrs) { super(context, attrs); // 加载布局 LayoutInflater.from(context).inflate(R.layout.view_top, this); // 获取控件 top_left = (ImageView) findViewById(R.id.top_left); top_title = (TextView) findViewById(R.id.top_title); top_right = (TextView) findViewById(R.id.top_right); } // 为左侧返回按钮添加自定义点击事件publicvoid setOnclickLeft(OnClickListener listener) { top_left.setOnClickListener(listener); } // 设置标题的方法publicvoid setTitle(String title) { top_title.setText(title); } // 设置标题的方法publicvoid setRightTitle(String title) { top_right.setText(title); } }
调用方法:
<com.example.lenovo.deeplove.TopView android:id="@+id/top_view" android:layout_width="match_parent" android:layout_height="wrap_content" />
完毕。
原文:https://www.cnblogs.com/geeksongs/p/10771535.html
内容总结
以上是互联网集市为您收集整理的安卓开发笔记(二十九):顶部导航栏全部内容,希望文章能够帮你解决安卓开发笔记(二十九):顶部导航栏所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。