대학 생활/Android
[Android] 커스텀 타이틀바 만들기
opid
2014. 3. 5. 16:52
참고사이트
res - 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="match_parent"
android:background="#505050" >
<TextView
android:id="@+id/titleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/msg"
android:textColor="#ffffff"
android:textSize="14sp" />
<ImageButton
android:id="@+id/btnMap"
android:layout_width="80px"
android:layout_height="80px"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:adjustViewBounds="true"
android:background="@drawable/button_map"
android:padding="0sp"
android:scaleType="centerCrop" />
</RelativeLayout>
res - values - style.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>
AndroidManifest.xml 수정
작성한 CustomTitle을 적용한다.
<activity
android:name="com.Test.MainActivity"
android:theme="@style/CustomTitle">
...
Activity.java 수정
작성한 CustomTitle을 적용한다.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// requestWindowFeature(Window.FEATURE_NO_TITLE);
// custom title bar
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);