티스토리 뷰

화면마다 동일한 타이틀바가 필요하여 구글링하여 커스텀 타이틀바를 만들어 보았다. 허접하다..


1. 타이틀바 layout 만들기 


<custom_title.xml>

 

<?xml version="1.0" encoding="UTF-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:background="@android:color/background_dark>

    <Button android:id="@+id/backBtn" 

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignParentLeft="true"

        android:layout_centerVertical="true"

        android:layout_marginLeft="5dp"

        android:text="@string/btn_back" />

    

    <TextView android:id="@+id/titleTextView"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_centerInParent="true"

        android:textSize="18sp" />

    

    <Button android:id="@+id/nextBtn" 

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignParentRight="true"

        android:layout_centerVertical="true"

        android:layout_marginRight="5dp"

        android:text="@string/btn_next" />

    

</RelativeLayout>


 

2. values폴더의 styles.xml 에 테마 관련 정보 추가하기

 

<style name="CustomTitle" parent="android:Theme">

<item name="android:windowTitleSize">48dp</item>    

<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>

</style>

    

<style name="CustomWindowTitleBackground">

<item name="android:background">#00000000</item>

</style>

 

 

3. AndroidManifest.xml 에 테마 설정하기 


<activity 

android:name=".Activity"

android:theme="@style/CustomTitle" />


 

4.  Activity.java에 다음 코드 넣기 


@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

setContentView(R.layout.main);

getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);

 

...

 

}



댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
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 30 31
글 보관함