1. 编写标题栏的layout.xml
<?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="wrap_content" android:background="@drawable/title_bg"> <Button android:id="@+id/title_back" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margin="5dp" android:background="@drawable/back_bg" android:text="Back" android:textColor="#fff" /> <TextView android:id="@+id/title_text" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_weight="1" android:gravity="center" android:text="Title Text" android:textColor="#fff" android:textSize="24sp" /> <Button android:id="@+id/title_edit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margin="5dp" android:background="@drawable/edit_bg" android:text="Edit" android:textColor="#fff" /> </LinearLayout>
2. 创建自定义控件类
public class MyLayout extends LinearLayout{ public MyLayout(Context context, AttributeSet attrs) { super(context, attrs); LayoutInflater.from(context).inflate(R.layout.title, this); Button titleBack = (Button) findViewById(R.id.title_back); Button titleEdit = (Button) findViewById(R.id.title_edit); titleBack.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ((Activity) getContext()).finish(); } }); titleEdit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getContext(), "You clicked Edit button", Toast.LENGTH_SHORT).show(); } }); } }
3.在需要使用自定义标题栏的activity的布局文件中,添加如下代码:
//标题栏布局文件的路径名一定要完整
<aispeech.learn1.MyLayout android:layout_width="match_parent" android:layout_height="wrap_content" />
4.隐藏系统的标题栏
//在使用自定义标题栏的activity中,隐藏标题栏
getSupportActionBar().hide();
相关推荐
在vc开发中经常用到自定义标题栏,但是通常不清楚如何更改里面的内容,比如如何覆盖标题栏的背景,如何添加自定义的放大,缩小、关闭按钮并添加相应的响应函数,如何放入自定义的图标,如何在标题栏上绘制曲线,我的...
本资源实现了一种wpf在style中自定义标题栏无边框窗口的方法。style内部的实现其实没那么简单,尤其是实现按钮逻辑以及拖动逻辑,需要在style中关联cs代码,这就要求我们熟悉绑定技巧、附加属性还有ContentPresenter...
android自定义标题栏源码,自定义view
自定义标题栏可缩放的QDialog,作为基类被继承,方便快捷第制作自定义的界面。
QT快速开发自定义标题栏示例,非常简单,使用方法如下: 1、目标窗口添加标题栏、最大化最小化关闭按钮(该步最好每次使用时,从模板程序中直接复制) 2、窗口基类从QDialog改为QFramelessDialog 3、窗口构造函数中...
上一章我们实现了在style中自定义标题栏,解决了复用性的问题。但是在实际使用中,还是存在一些问题的,比如有些界面需要放几个菜单在标题栏或者不需要最大化按钮等,就会变得很不灵活。这时候就需要对style进行...
自定义标题栏源码,实现了 1.鼠标左键点击移动 2.最小化 最大化/恢复 关闭程序功能 3.双击鼠标最大化/恢复功能 ************************************************************************************************...
利用Qt实现自定义标题栏功能(自定义最大化、最小化、关闭等功能),自定义标题栏,可以自己设计按键的大小,图标,位置,能够和背景更加统一,详细内容可参考文章:...
android studio 自定义标题栏,自定义回退按钮事件,自定义右侧显示文字还是图片,自定义右侧点击事件
xamarin android自定义标题栏,希望能够帮助到大家。。
【Qt】仿360安全卫士界面(自定义标题栏).rar
自定义标题栏 修该 高度 以及 处理没有完全填充bug。
7、如何自定义标题栏?(Visual C++编程 源代码)7、如何自定义标题栏?(Visual C++编程 源代码)7、如何自定义标题栏?(Visual C++编程 源代码)7、如何自定义标题栏?(Visual C++编程 源代码)7、如何自定义...
Android自定义标题栏,需要的童鞋可以下来看看。
初学者项目需要,自己封装的一个qt自定义标题栏,可以直接调用。环境是vs2013+qt5.6.2,其他环境我也不知道能否使用,谨慎下载。 大部分标题栏的显示效果都放在paintEvent函数中,可以动态更改。大部分效果都写了...
本源代码是用Qt5.9的Creator编译和构建,主要功能是实现自定义标题栏,而屏蔽系统自带的标题栏。具体的讲解和用法可以参考我的博客:https://blog.csdn.net/naibozhuan3744/article/details/81120544
uni-app-自定义标题栏示例.zip
Android复合控件学习之自定义标题栏;学习自定义属性、接口回调等知识点
用qt5写的自定义标题栏,做相应的改变也可以在其他版本运行,去掉了系统默认的标题栏,自己实现关闭,最大化,最小化,双击最大化最小化功能,这对标题栏的美化有帮助