Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8705929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:29:10+00:00 2026-06-13T03:29:10+00:00

I have an application that needs the same items [5 buttons acting as tabs]

  • 0

I have an application that needs the same items [5 buttons acting as tabs] in every screen. Is it possible to create a “base XML layout” that has these 5 buttons and then have all the other XML files extend from the bas layout in some way so that I don’t have to have multiple buttons that will ultimately have the same functionality.

Is there a better approach to this problem that can be supported by API 9

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:29:11+00:00Added an answer on June 13, 2026 at 3:29 am

    Create a common layout for your base activity. and then include that layout in all the layout using the <include> tagwhich you want to make the same.

    After that create one Abstract Activity and then handle all the click of the buttons and code in this activity and then extends this activity in all other activity in which you have include the base layout.

    For example

    common buttons xml layout

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/tabhost_bg"
        android:gravity="center"
        android:orientation="horizontal" 
        android:weightSum="3">
    
        <Button
            android:id="@+id/btnHome"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/bottom_btn_active" 
            android:layout_weight="1"
            android:text="@string/label_home"
            style="@style/bottom_tab_btn"/>
    
        <Button
            android:id="@+id/btnSetting"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/bottom_btn_active" 
            android:layout_weight="1"
            android:text="@string/label_settings"
            style="@style/bottom_tab_btn"/>
    
        <Button
            android:id="@+id/btnMore"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/bottom_btn_active" 
            android:layout_weight="1"
            android:text="@string/label_more"
            style="@style/bottom_tab_btn"/>
    
    </LinearLayout>
    

    Here is a xml layout in which you can include above XML file

    <include
            android:id="@+id/bottombar"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            layout="@layout/bottom_bar" />
    

    Here android:layout_width and android:layout_height and layout are compulsory attributes

    Now here is a Base Activity which handles the click of the common controls

    public abstract class BottomBar extends Activity implements OnClickListener {
    
        protected Button btnHome;
        Button btnSetting, btnMore;
        private Activity mActivity;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            mActivity = this;
        }
    
        protected void mappingWidgets() {
    
            btnHome = (Button) findViewById(R.id.btnHome);
            btnSetting = (Button) findViewById(R.id.btnSetting);
            btnMore = (Button) findViewById(R.id.btnMore);
    
            btnHome.setOnClickListener(this);
            btnSetting.setOnClickListener(this);
            btnMore.setOnClickListener(this);
        }
    
        @Override
        public void onClick(View v) {
            if (v == null)
                throw new NullPointerException(
                        "You are refering null object. "
                                + "Please check weather you had called super class method mappingWidgets() or not");
            if (v == btnHome) {
    
            } else if (v == btnSetting) {
    
            }else if(v == btnMore) {
    
            }
        }
    
        protected void handleBackgrounds(View v) {
            if (v == btnHome) {
                btnHome.setBackgroundResource(R.drawable.bottom_btn_hover);
                btnSetting.setBackgroundResource(R.drawable.bottom_btn_active);
                btnMore.setBackgroundResource(R.drawable.bottom_btn_active);
    
            } else if (v == btnSetting) {
                btnHome.setBackgroundResource(R.drawable.bottom_btn_active);
                btnSetting.setBackgroundResource(R.drawable.bottom_btn_hover);
                btnMore.setBackgroundResource(R.drawable.bottom_btn_active);
    
            } else if (v == btnMore) {
                btnHome.setBackgroundResource(R.drawable.bottom_btn_active);
                btnSetting.setBackgroundResource(R.drawable.bottom_btn_active);
                btnMore.setBackgroundResource(R.drawable.bottom_btn_hover);
            }
        }
    
    }
    

    Now one step remaining is to extend this Base activity in all your activities.

    You can extend the Base activity in an activity using the extends keyword.
    For example

    public class MyActivity extends BottomBar
    

    Note: From the child activity you must call the super method of the base class to handle the click of the common controls of your base layout.

    You can thus implement multiple common layout within your single activity.

    Hope this will help you.
    Enjoy!!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that needs updating constantly. I would like to create a
I have an application that needs to check a website feed every second. Sometimes
I have an application that needs to copy, remove, modify, etc. files in the
I have an application that needs to work with a vendor-supplied API to do
I have an application that needs to highlight individual pixels on an image. I
I have an application that needs to determine whether a user has made a
I have an application that needs branding when downloaded in certain continents. When installed
I have an application that needs to operate on Windows 2000. I'd also like
imagine a situation where you have an application that needs to import data from
I have an ExtJS application that needs to display an html document within a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.