How to add padding to a tabs label?

前端 未结 3 896
死守一世寂寞
死守一世寂寞 2020-12-20 04:30

I just started programming for android. I\'m using a tab based layout in my app. I would like to put some padding around the tab label so that it\'s not so close to the icon

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-20 05:04

    tabHost.addTab(tabHost.newTabSpec("tab1").setContent(
                new Intent(this, DealCities.class)).setIndicator(prepareTabView("Deals",R.drawable.deal)));
    

    Where prepareTabView is a method.. In these method Inflate a view and add Image and Text as follows :

    private View prepareTabView(String text, int resId) {
        View view = LayoutInflater.from(this).inflate(R.layout.tabs, null);
        ImageView iv = (ImageView) view.findViewById(R.id.TabImageView);
        TextView tv = (TextView) view.findViewById(R.id.TabTextView);
        iv.setImageResource(resId);
        tv.setText(text);
        return view;
    }
    

    Where tabs is the inflated view and its xml as follows :

    
    
    
    
    
    
    

    Now you can make Your Paddings as you like..

提交回复
热议问题