0

what I am trying to do is to show a menu bar at any time no matter what layout or Activity is being displayed. What I'm basically doing is create an activity (lets call it MenuActivity), that creates the buttons, and make the other activities extend from MenuActivity. The problem is, I cant find a way to make the buttons get displayed on the other activities. Here is the xml of the buttos if this helps:

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/relativeLayout" >

    <Button
        android:id="@+id/ABC"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="14dp"
        android:layout_y="373dp"
        android:text="@string/abc" />

    <Button
        android:id="@+id/favoritos"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="62dp"
        android:layout_y="374dp"
        android:text="@string/favoritos" />

    <Button
        android:id="@+id/Cupones"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="243dp"
        android:layout_y="372dp"
        android:text="@string/cupones" />

    <Button
        android:id="@+id/destacados"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="145dp"
        android:layout_y="375dp"
        android:text="@string/destacados" />

</AbsoluteLayout>

Thanks in advance!

Carlos Tirado
  • 297
  • 1
  • 5
  • 20
  • Seriously!! you are using AbsoluteLayout which was deprecated a long time ago??? – Andro Selva Jul 18 '12 at 04:26
  • This is not the way to display a menu bar. Use ActionBar. Look in Android developer docs for ActionBar. If you are targeting pre-HoneyComb; use ActionbarSherlock library (http://abs.io). – curioustechizen Jul 18 '12 at 04:44

1 Answers1

1

I guess that your problem will be solved if you include this layout as child layout in layout of other Activities:

<include  layout="@layout/menulayout" android:id="@+id/menuLayout"  ...  />

The menulayout.xml is name of your above layout that should be defined in res/layout and you like that be shown as menu in all Activities,also menuLayout is id of your menulayout and you can reference to it in your Activity's layout or in your code.
You can override all the layout parameters. This means that any android:layout_* attribute can be used with the <include /> tag. Here is an example:

<include android:layout_width="fill_parent" layout="@layout/image_holder" />     

You can see more details in about include in this page.
Edit:
If you have problems in about finding views in included layout,see this questions,I hope these help you:
findViewById not working for an include?
Finding an view by id?

Community
  • 1
  • 1
hasanghaforian
  • 13,858
  • 11
  • 76
  • 167