So erstellen Sie benutzerdefinierte Menü in ein layout in android?

Erstellen Sie ein angepasstes Menü und legen das Menü in einem bestimmten layout ist in der Mitte des RelativeLayout, ich habe versucht, es zu machen, aber hat nicht funktioniert:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Home" >

  <LinearLayout
        android:id="@+id/grid1"
        android:layout_width="750dp"
        android:layout_height="400dp"
        android:background="@android:color/darker_gray"
        android:layout_centerInParent="true"
        android:orientation="vertical" >

   <menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:id="@+id/Main"
          android:title="@string/main"/>
    <item android:id="@+id/Sub"
          android:title="@string/sub"/> 
   </menu>

  </LinearLayout>

</RelativeLayout>

in Java:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        //Inflate the menu; this adds items to the action bar if it is present.
        //RelativeLayout layout = (RelativeLayout) findViewById(R.layout.activity_home);

        getMenuInflater().inflate(R.menu.home, menu);
        return true;
    }

P. s ich auch versucht, es in eine separate Datei und fügen Sie es aber, wenn Sie tun, dass es nur in der actionbar.

InformationsquelleAutor MRefaat | 2013-11-21
Schreibe einen Kommentar