Android状态栏与标题融合,android自定义状态标题

1.在activity中设置:

注意: supportRequestWindowFeature(Window.FEATURE_NO_TITLE); 该代码要放置在 setContentView(R.layout.activity_main);前才能起作用


//主activity界面:
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);
    //去除原有标题 
    supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_main);

    //将背景图与状态栏融合
    if (Build.VERSION.SDK_INT >= 21) {
        View decorView = getWindow().getDecorView();
        decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        getWindow().setStatusBarColor(Color.TRANSPARENT);
    }}

 

2.xml 界面 activity_main:layout界面

如果要状态栏与标题留空隙 需要 加上 android:fitsSystemWindows="true"  状态栏与标题留空隙作用

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:background="@mipmap/xingkong"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">
    
    <!--android:fitsSystemWindows="true"  状态栏与标题留空隙作用-->
    <!--标题布局界面如下-->

    <include layout="@layout/titlebar"/>

</LinearLayout>


3.titlebar:layout 自定义状态栏布局界面

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize">


    <TextView
        android:id="@+id/co_tv_back"
        android:layout_centerVertical="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/colorWhite"
        android:text="返回"
        android:textSize="24sp"
        android:layout_alignParentLeft="true"
        />
    <TextView
        android:id="@+id/co_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:textSize="26sp"
        android:textColor="@color/colorWhite"
        android:text="帖子详情"
        />

    <ImageView
        android:id="@+id/co_img_edit"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_centerVertical="true"
        android:layout_toLeftOf="@+id/co_img_del"
        android:layout_marginRight="20dp"
        android:scaleType="fitXY"
        android:background="@mipmap/edit" />
    <ImageView

        android:id="@+id/co_img_del"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_centerVertical="true"
        android:layout_alignParentRight="true"
        android:scaleType="fitXY"
        android:background="@mipmap/del" />

</RelativeLayout

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值