0

For my app, I am trying to put buttons at the bottom of all activities similar to WeChat app as can be seen in below image:

enter image description here

Now one way I thought of is simply adding <ImageButton>s at bottom of each activities but I don't think WeChat does that because you can swipe between activities and there is no onCreate triggered, activities are always there that are simply switched when swiped or touched on specific button.

I did research and found out one can use split action bar or even ViewFlipper. Action bar splitting is out of question since button will be moved back to action bar for example in landscape mode since I want to have buttons always appear at bottom like WeChat. Another option I saw was Tabbed interface but I saw with it, it can appear below actionbar unlike WeChat where even actionbar is changed based on activity.

Question: Does anyone know what does WeChat use for this functionality so I can implement the same ?

Dev01
  • 4,082
  • 5
  • 29
  • 45
  • Use a Fragment TabHost: http://envyandroid.com/archives/326/align-tabhost-at-bottom – Phantômaxx Jan 06 '15 at 11:15
  • I dont know what weChat is used for this but for sure you can get the same output using "Tabhost". – Remees M Syde Jan 06 '15 at 11:20
  • One RelativeLayout horizontally for all ImageButtons, and align it bottom, also you can set background color for the 'RelativeLayout' – Xcihnegn Jan 06 '15 at 11:33
  • I did something similar using ViewPager in the v4 support library and my own buttons at the bottom of the activity, handling the various callbacks myself. I needed to support down to api level 8. – Gravitoid Jan 07 '15 at 15:03

2 Answers2

1

One Idea is create BaseActivity, in which include the general design you prefer throughout the App. In other activities, extend BaseActivity. You can also extend Activity class in some activities where no need to show the buttons, such as LoginActivity.

Vilas
  • 1,695
  • 1
  • 13
  • 13
1
here is code main class 


public class TabSample extends TabActivity {
    /** Called when the activity is first created. */

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        setTabs();

    }

    private void setTabs() {

        addTab("Wechat", R.drawable.tab_home, ShowList.class);
        addTab("Social", R.drawable.tab_search, UploadVideo.class);

        addTab("Contact Us", R.drawable.tab_home, Contactus.class);
        addTab("Setting", R.drawable.tab_search, DoNotDo.class);




    }

    private void addTab(String labelId, int drawableId, Class<?> c) {
        TabHost tabHost = getTabHost();
        Intent intent = new Intent(this, c);
        TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);

        View tabIndicator = LayoutInflater.from(this).inflate(
                R.layout.tab_indicator, getTabWidget(), false);
        TextView title = (TextView) tabIndicator.findViewById(R.id.title);
        title.setText(labelId);
        ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
        icon.setImageResource(drawableId);

        spec.setIndicator(tabIndicator);
        spec.setContent(intent);
        tabHost.addTab(spec);
    }
}

here is xml

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:background="#ffffff"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1" />

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="2dp"
            android:layout_weight="0" />

    </LinearLayout>

</TabHost>
param
  • 393
  • 6
  • 17
  • Just as an FYI, TabActivity was deprecated in api level 13. Docs suggest using fragments which are supported in v4 support library. http://developer.android.com/reference/android/app/TabActivity.html – Gravitoid Jan 07 '15 at 15:00