comment_toolbar.xml
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toobar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:navigationIcon="@drawable/back"
android:background="#000000"
>
</android.support.v7.widget.Toolbar>
main.xml
<include android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/toolbar"
/>
Activity
package com.imooc.food;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
/**
* Created by Administrator on 2018/3/13.
*/
public class BasicActity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT>Build.VERSION_CODES.LOLLIPOP){
getWindow().setStatusBarColor(0xff000000);
}
/**
* 判断版本如果大于21则标题栏显示黑色.
*/
}
protected void getToolBar(){
Toolbar toolbar=(Toolbar)findViewById(R.id.toobar);
setSupportActionBar(toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onBackPressed();
}
});
}
}
网友评论