android - How to add Action Bar in relativeLayout -
actually want put action bar menu layout given below, no getting how put action bar menu it. can me in fixing problem...
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="16dp" android:paddingright="16dp" android:id="@id/action_bar" > <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="enable pin" android:id="@+id/button" android:layout_marginbottom="140dp" android:layout_alignparentbottom="true" android:layout_alignend="@+id/button2" android:layout_alignstart="@+id/button2" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="enable pattern" android:id="@+id/button2" android:layout_alignparentbottom="true" android:layout_centerhorizontal="true" android:layout_marginbottom="51dp" /> </relativelayout>
first must use tool bar because action bar deprecated , add below code layout
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@drawable/back"> <android.support.v7.widget.toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionbarsize" android:background="?attr/colorprimary" android:fitssystemwindows="true" /> <!-- add other layout component here --> </linearlayout>
and in activity must extend form appcompactactivity below:
public class mainactivity extends appcompatactivity { private toolbar toolbar; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.yourlayout); toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); } }
and in style.xml add code: specially parent="theme.appcompat.light.noactionbar"
<style name="apptheme" parent="theme.appcompat.light.noactionbar"> <item name="colorprimary">@color/primary</item> <item name="colorprimarydark">@color/primary_dark</item> <item name="coloraccent">@color/accent</item> </style>
Comments
Post a Comment