Coder Social home page Coder Social logo

titlebar's Introduction

titlebar

一个简单易用的导航栏TitleBar,可以轻松实现IOS导航栏的各种效果 整个代码全部集中在TitleBar.java中,所有控件都动态生成,动态布局。不需要引用任何资源文件,拷贝TitleBar.java到自己工程即可使用 alt text

1. 左边文字,左边返回图片,左边点击事件

左边可设置图片,文字单独显示,也可以设置图片文字同时显示
titleBar.setLeftImageResource(R.mipmap.back_green);
titleBar.setLeftText("返回");
titleBar.setLeftTextColor(Color.WHITE);
titleBar.setLeftClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        finish();
    }
});

2. 中间文字

中间文字根据左右控件始终居中显示,自动排版
titleBar.setTitle("文章详情");
titleBar.setTitleColor(Color.WHITE);

3. 右边action按钮或者文字

通过addAction添加操作控件,通过removeAction删除控件。可以使用图片或者文字。
titleBar.setActionTextColor(Color.WHITE);
mCollectView = (ImageView) titleBar.addAction(new TitleBar.ImageAction(R.mipmap.collect) {
    @Override
    public void performAction(View view) {
        Toast.makeText(MainActivity.this, "点击了收藏", Toast.LENGTH_SHORT).show();
        mCollectView.setImageResource(R.mipmap.fabu);
    }
});

titleBar.addAction(new TitleBar.TextAction("发布") {
    @Override
    public void performAction(View view) {
        Toast.makeText(MainActivity.this, "点击了发布", Toast.LENGTH_SHORT).show();
    }
});

4. 下划分割线

titleBar.setDividerColor(Color.GRAY);

5. 一行代码适配沉浸式

如果你的项目使用了沉浸式,布局时候加上这行代码,TitleBar会自动填充状态栏
titleBar.setImmersive(true);

6. 一行代码设置TitleBar高度

如果你的TitleBar没有固定高度,会默认设置48dip作为高度,你也可以自定义高度
titleBar.setHeight(48 * 2);

7. 设置简单的副标题

如果TitleBar分主副标题,用\n和\t区分,如果\n,主副标题上下排列,如果\t,主副标题左右排列
titleBar.setTitle("文章详情\n副标题");
titleBar.setTitle("文章详情\t副标题");

我的创业项目,创业不易,有需要的可以支持下哦~

alt text

titlebar's People

Contributors

bacy avatar bryant1410 avatar huopochuan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.