Android MD (Material Design)设计
1:Android ActionBar 使用系统风格
1: ActionBar是google给用户提供了一种全局统一的界面风格和操作方式
2:如何修改系统的ActionBar风格,并定义成自己的 ActionBar风格,首先我们知道ActionBar可以添加自定义的布局样式(setCustomView),那么突破口就在这里了,我们可以通过自定义布局样式,在这个布局文件里面添加我们需要在ActionBar上面显示的标题和控件等
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setCustomActionBar();
}
private void setCustomActionBar() {
ActionBar.LayoutParams lp =new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT, Gravity.CENTER);
View mActionBarView = LayoutInflater.from(this).inflate(R.layout.actionbar_layout, null);
ActionBar actionBar = getActionBar();
actionBar.setCustomView(mActionBarView, lp);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="标题"
android:textColor="#ffffff"/>
</RelativeLayout>