1.点开AndroidManifest.xml中android:theme="@style/AppTheme">对下的代码,
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
2.布局代码
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" android:background="@color/整个背景图" android:layout_height="match_parent"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:background="@drawable/头部背景图" app:contentInsetStart="0dp" android:layout_width="match_parent" android:layout_height="wrap_content"> .......
3.Fragment代码内容
@SuppressLint("ValidFragment") public class Index extends BaseFragment implements AppBarLayout.OnOffsetChangedListener { Toolbar toolbar; public Index(Context context) { super(context); } @Override public View initView() { View view = View.inflate(context, R.layout.activity_index,null); toolbar = (Toolbar) view.findViewById(R.id.toolbar); return view; } @Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { toolbar.setVisibility(View.VISIBLE); }
4.好心累,终于搞定了