How the custom the ActionBar by using xml in Android?



I am try to custom the ActionBar by using xml in Android.


The actionbat.xml is like the following:



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bar_background" >

<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/bar_icon"/>

</RelativeLayout >


And I using the following code to set ActionBar in Fragment



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.function_list, container, false) ;

ActionBar bar = getActivity().getActionBar();
bar.setCustomView(R.layout.actionbar);


But the ActionBar didn't change anything , did I missing something ?


Thanks in advance.


No comments:

Post a Comment