自定义的标题栏和隐藏ActionBar
来源:互联网 发布:aws php sdk 编辑:程序博客网 时间:2024/06/05 14:26
首先要了解什么事状态栏什么事actionbar这里我们要隐藏的是ActionBar不是状态栏
在AndroidManifest.xml里面改变application的theme的属性改变成@style/Theme.AppCompat.Light.NoActionBar
现在的android studio里面的类多数是继承的AppCompatActivity所以在使用之前隐藏activity的方发就不好使了
下面讲一下自定义的一个标题栏
首先创建一个类继承RelativeLayout
就拿今日头条的标题栏做例子
先看一下布局很简单
<?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="42dp"
android:background="#c83c23"
>
<ImageView
android:layout_marginLeft="12dp"
android:id="@+id/title_img_left"
android:layout_width="42dp"
android:layout_height="42dp"
android:src="@drawable/default_sdk_login"
android:layout_alignParentLeft="true"
/>
<TextView
android:layout_toLeftOf="@+id/title_img_right"
android:layout_toRightOf="@+id/title_img_left"
android:id="@+id/title_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="今日头条"
android:textColor="#fff"
android:textSize="24dp"
/>
<ImageView
android:id="@+id/title_img_right"
android:layout_width="42dp"
android:layout_height="match_parent"
android:src="@drawable/search_toast_ab"
android:layout_alignParentRight="true"
android:layout_marginRight="12dp"
/>
</RelativeLayout>
这是布局的文件
下面看一下代码
public class Title_View extends RelativeLayout {
private TextView title_text;
private ImageView title_img_left;
public Title_View(Context context) {
super(context);
initview(context);
}
private void initview(Context context) {
LayoutInflater.from(context).inflate(R.layout.activity_title, this);
title_text = (TextView) findViewById(R.id.title_text);
title_img_left= (ImageView) findViewById(R.id.title_img_left);
}
//设置左侧imageview点击事件
public void setLeftlistener(OnClickListener listener) {
findViewById(R.id.title_img_left).setOnClickListener(listener);
}
//设置右侧imageview点击事件
public void setRightlistener(OnClickListener listener) {
findViewById(R.id.title_img_right).setOnClickListener(listener);
}
//设置标题
public void setTitle(String text) {
title_text.setText(text);
}
public Title_View(Context context, AttributeSet attrs) {
super(context, attrs);
initview(context);
}
public Title_View(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
}
在要使用这个标题的布局文件的地方调用
如果要设施点击事件的话就直接调用你自定义类里的方法就可以
阅读全文
0 0
- 自定义的标题栏和隐藏ActionBar
- 如何隐藏ActionBar的标题栏
- 如何隐藏ActionBar的标题栏
- 安卓取消标题栏和隐藏ActionBar
- 隐藏ActionBar标题栏
- Android 隐藏活动的ActionBar(隐藏活动标题栏)
- Android Actionbar自定义标题栏
- ActionBar 去掉标题栏 自定义
- Android自定义标题栏ActionBar
- android ActionBar自定义标题栏
- android隐藏标题栏Actionbar的两种方式
- 标题栏的实现ActionBar和toolBar
- 顶部标题栏(四)自定义ActionBar风格和样式
- Android基础--ActionBar的基本用法,自定义View,标题栏
- Android:Actionbar的显示和隐藏
- 15 Actionbar的显示和隐藏
- 设置全屏和隐藏标题栏的方法
- android状态栏和标题栏的隐藏
- 实现把字典转换为XML数据
- App适配iOS 11
- Eclipse找不到zipalign tool,找不到hprof-conv.exe
- Android WebView与JS页面相互调用(五)
- JPA的几个常用方法
- 自定义的标题栏和隐藏ActionBar
- 查询数量 简单分析count(1) count(*)以及count(column)的区别
- Mac OSX的开机启动配置
- nignx.conf常规配置
- ACM退役帖(青岛赛后再更新)
- Javascript简单设计模式
- 史上最简单的生成验证码
- 表单实现<form>
- HDU 4745 Two Rabbits 最长回文子序列