반응형

・ 다음과 같은 파란색 라인을 없애는 방법입니다.

・ customTab을 제작하여 각 Tab에 덮어씌우는 방식입니다.


custom_tab.xml

  • Layout파일을 만들어서 Tab에 보여주고 싶은 구성으로 레이아웃을 꾸며준다.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
 
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center_vertical">
 
        <ImageView
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:id="@+id/imageView"
            android:layout_gravity="center_horizontal"
            android:background="@drawable/homeicon" />
 
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="15dp"
            android:text="HOME"
            android:id="@+id/textView"
            android:layout_gravity="center_horizontal" 
            android:background="@drawable/homeicon_text"/>
    </LinearLayout>
</LinearLayout>
 
cs


myTab.java
  • TabHost를 작성한 java파일에 다음의 코드를 작성한다.
  • Inflater를 사용하여 위에서 정의한 xml파일을 inflate한다.
  • 만들어진 inflater를 View 객체를 만들어서 뿌려준다.

1
2
3
4
5
6
7
8
9
10
        TabHost.TabSpec spec1 = tabHost.newTabSpec("HOME");
        intent1 = new Intent(this,MainActivity.class);
        spec1.setContent(intent1);
 
        LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = (View)inflater.inflate(R.layout.custom_tab,null);
        spec1.setIndicator(v);
 
 
        tabHost.addTab(spec1);
cs


결과




반응형
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기