Create tabs like Twitter or Instagram to work on all Android> 2.2 platforms

I read several articles here. How to create such bookmarks for Android (screenshot)?

Further in the comments there is sherlock lib, which brings a 4.0 look at devices with Android 2.2.

My problem is that I am trying to make "ugly" :) an old look for working on new devices.

Something like an image:

enter image description here

So, I would like to have tabs, no action bars, only 5 boxes with images and text, which is preferably a string, since it should be localized.

So, I use, and inside tablayout.xml I set the title (from the line), and programmatically I add the image to a specific tab from my resources.

th.setup(); TabSpec specs = th.newTabSpec("tag1"); //specs.setContent(new Intent(this,MyAppTab.class)); specs.setContent(R.id.tab1); specs.setIndicator(getResources().getString(R.string.tab_myapp_title), getResources().getDrawable(R.drawable.ic_tab1_active)); 

What is happening now is on my Android 2.2. phone, it looks ugly, but with an image, like what I would like to have, and on my wife 4.0. I see new tabs with text.

How to add tab image to work in all versions of Android?

Tpx

+6
source share
1 answer

You can use the custom view as a tab indicator with this method .

  • Fill custom view
    • View yourView = inflater.inflate(R.layout.my_tab_indicator, null);
  • Fill it up
    • ((ImageView) yourView.findViewById(R.id.tab_indicator_icon)).setBitmapRessource(...)
    • ((TextView) yourView.findViewById(R.id.tab_indicator_title)).setText(...)
  • call tabSpec.setIndicator(yourView);
0
source

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


All Articles