【MVP】与toolbar相关的实现+progressWheel进度条

来源:互联网 发布:linux中怎么创建文件 编辑:程序博客网 时间:2024/05/29 19:17

自我学习使用,共同进步
之前先要除去系统的状态栏

  <style name="Theme.AppCompat.Light.NoActionBar">        <item name="windowActionBar">false</item>        <item name="windowNoTitle">true</item>    </style>

再写view_toolbar.xml布局文件,包含toolbar和ProgressWheel

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:wheel="http://schemas.android.com/apk/res-auto"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:orientation="vertical">    <RelativeLayout        android:layout_width="match_parent"        android:layout_height="wrap_content">        <android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"            android:id="@+id/toolbar"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:background="@color/blue"            app:theme="@style/ToolbarStyle" />        <com.xiaoyuan.hloli.weiget.view.ProgressWheel            android:id="@+id/progressWheel"            android:layout_width="25dp"            android:layout_height="45dp"            android:layout_alignParentRight="true"            android:layout_centerVertical="true"            android:layout_marginRight="20dp"            wheel:matProg_barColor="@color/white"            wheel:matProg_barWidth="2dp" />    </RelativeLayout></LinearLayout>

在写Java文件

 @Bind(R.id.toolbar)    @Nullable    Toolbar toolbar;    @Bind(R.id.progressWheel)    @Nullable    ProgressWheel progressWheel;    public void initBaseToolbar(int titleResId,Boolean canBack){        assert toolbar != null;        toolbar.setTitle(titleResId);        toolbar.setTitleTextColor(Color.WHITE);        setSupportActionBar(toolbar);        if(canBack && getSupportActionBar() != null){            getSupportActionBar().setHomeButtonEnabled(true); //设置返回键可用            getSupportActionBar().setDisplayHomeAsUpEnabled(true);        }    }    public void initBaseToolBar(String titleStr, boolean canBack) {        assert toolbar != null;        toolbar.setTitle(titleStr);        toolbar.setTitleTextColor(Color.WHITE);        setSupportActionBar(toolbar);        if (canBack && getSupportActionBar() != null) {            getSupportActionBar().setHomeButtonEnabled(true); //设置返回键可用            getSupportActionBar().setDisplayHomeAsUpEnabled(true);        }    }    public void showLoading(){        if (progressWheel != null && !progressWheel.isSpinning()){            progressWheel.isSpinning();        }    }    public void stopLoading(){        if (progressWheel !=null&&  progressWheel.isSpinning()){            progressWheel.stopSpinning();        }    }