Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think the best way to solve your issue is with inheritance. If you define an Activity that can be used as a template for all your fleshed out Activitys to add their content to. I don't know what you custom menu is 'made of' but as a simple example:</p> <p>Create a basic Activity with code:</p> <pre><code> public class ActivityWithMenu extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_with_menu_layout); } } </code></pre> <p>and xml:</p> <pre><code> &lt;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" tools:context=".ActivityWithMenu" &gt; &lt;TextView android:layout_width="match_parent" android:layout_height="20dip" android:background="#ff000000" android:textColor="#ffffffff" android:text="Main Menu Title Bar" android:id="@+id/mainmenutitle" /&gt; &lt;LinearLayout android:layout_width="20dip" android:layout_height="match_parent" android:layout_below="@+id/mainmenutitle" android:layout_alignParentLeft="true" android:background="#ff999999" android:orientation="vertical" android:id="@+id/lefthandmenu" /&gt; &lt;LinearLayout android:layout_width="20dip" android:layout_height="match_parent" android:layout_below="@+id/mainmenutitle" android:layout_alignParentRight="true" android:background="#ff999999" android:orientation="vertical" android:id="@+id/righthandmenu" /&gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_toLeftOf="@+id/righthandmenu" android:layout_toRightOf="@+id/lefthandmenu" android:layout_below="@+id/mainmenutitle" android:orientation="vertical" android:id="@+id/activitycontent" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>Then create your xml for a specific Activity, in this case a simple 'Hello World' layout:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="vertical" &gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#ff00ff00" android:text="Hello World!" /&gt; &lt;/LinearLayout&gt; &lt;/ScrollView&gt; </code></pre> <p>But now when you write the code for this Activity, extend 'ActivityWithMenu' instead of the Activity class direct and inflate this xml layout as follows:</p> <pre><code> public class Activity1 extends ActivityWithMenu { @Override protected void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); super.onCreate(savedInstanceState); LinearLayout ll = (LinearLayout)findViewById(R.id.activitycontent); ScrollView sv = (ScrollView)this.getLayoutInflater().inflate(R.layout.activity1_layout, ll, false); ll.addView(sv); } } </code></pre> <p>I have added the code for making the Activity fullscreen here instead of in the parent ActivityWithMenu class assuming that you wouldn't want them all displayed that way but you could move it into the parent class if appropriate.</p> <p>Hope this helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload