Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COI've got a layout called `menu_view` where I have desgined the menu wich is formed by 2 columns with buttons on the laterals, and a custom title bar. Then, a class called `menuView` too where I define all the button's onClickListeners, but this class `extends RelativeLayout`. here i use the layout inflater, and then to insert this menu on other layouts I simply define it on the wanted layout. I see that you say to extend this menu class as an activity, but is this compatible with what I'm doing?
      singulars
    2. COI don't see why not, after a little bit of a re-structure. If you change my 'lefthandmenu'/'righthandmenu' with the layout xml for your columns of buttons and the 'mainmenutitle' with your title xml, just leave the arrangement properties like 'toLeftOf' etc and it should display the same. And move your onClickListener setup into the onCreate of the parent class ('ActivityWithMenu' in my example) and that way you need only have it in one place. I do think it will be easier doing it this way rather than trying to overlay such a complex interface control over every activity ad-hoc.
      singulars
    3. COFinally tried this way but I'm having one problem, it makes an error and the logcat say that the error is when inflating the "ActivityWithMenu" layout. It tells me that it makes that error in "ScrollView sv = (ScrollView)this.getLayoutInflater().inflate(R.layout.activity1_layout, ll, false);"
      singulars
 

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