Custom Tabs in Android

How to create custom tabs in android without using images? I need to create a tab like this ...

enter image description here

+4
source share
3 answers

I found the answer to my question in my own stack

refer to the answer made by Hardik Gajar in the following question:

How to create a central panel in android?

+2
source

You can associate the view with your tab:

tabHost.newTabSpec("name").setIndicator(R.id.your_view) 
+1
source

You need to create your own view for each tab button, and a different view for the camera tab. I think something like this:

 private void fillTabHost() { setupTab(ONE, new Intent().setClass(this, Activity.class), "title",R.drawable.icon); setupTab(TWO, new Intent().setClass(this, Activity.class), "title", R.drawable.icon); setupTab(THREE, new Intent().setClass(this, Activity.class), "title",R.drawable.icon); setupTab(FOUR, new Intent().setClass(this, Activity.class), "title",R.drawable.icon); setupTab(FIVE, new Intent().setClass(this, Activity.class), "title",R.drawable.icon); } private void setupTab(final String tag, Intent intent, int label, int icon) { View tabview = createTabView(tag, mContext, label, icon); TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(intent); mTabHost.addTab(setContent); } private static View createTabView(String tag, final Context context, final int text, final int icon) { if(tag.equals("THREE")){ // TODO return your CAMERA view }else{ View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null); ImageView iv = (ImageView) view.findViewById(R.id.tabsIcon); iv.setBackgroundResource(icon); TextView tv = (TextView) view.findViewById(R.id.tabsText); tv.setText(text); } return view; } 

Hope this helps you!

0
source

Source: https://habr.com/ru/post/1437164/


All Articles