Android UI TabActivity issue

后端 未结 2 1051
南旧
南旧 2020-12-06 08:19

I am trying to implement the following background for the application... \"enter

For t

相关标签:
2条回答
  • 2020-12-06 09:07

    For this you must use Custom Tabs ,here is the Code try this :

      tabHost= getTabHost();
      tabHost.addTab(tabHost.newTabSpec("tab1").setContent(new Intent(this, Activity2.class)).setIndicator(prepareTabView("Names",R.drawable.icon)));
    

    where prepareTabView is method that Inflate View. Then Inflate a view like this :

        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 XML will look like this :

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:id="@+id/TabLayout" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:padding="5dip">
    
    <ImageView android:id="@+id/TabImageView" android:src="@drawable/icon"           
     android:layout_width="wrap_content" android:layout_height="wrap_content"/>
    
    <TextView android:id="@+id/TabTextView" android:text="Text" 
    android:paddingTop="5dip" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:textColor="@color/black" 
    android:textAppearance="@style/TabTextViewStyle" />
    
     </LinearLayout>
    

    Then now add your backgroung color as you like..

    0 讨论(0)
  • 2020-12-06 09:17

    TabActivity is Deprecated from Android 4.2,API level 17. Use Fragments instead of TabActivity

    0 讨论(0)
提交回复
热议问题