Android > ActionBar - ½ºÅ¸ÀÏ ¹× Å׸¶ º¯°æÇϱâ
µî·ÏÀÏ : 2017-07-05 18:58
Á¶È¸¼ö : 53,850
Áö³¹ø¿¡ Action Bar¸¦ Ãß°¡ÇÏ´Â °Í±îÁö °øºÎ Çߴµ¥ À̹ø¿¡´Â Action Bar Style º¯°æ ¹× Å׸¶ º¯°æ ¹æ¹ýÀ» ¾Ë¾Æº¸°Ú½À´Ï´Ù.
±âº»ÀûÀ¸·Î ¼ÂÆõǴ Action BarÀÇ »ö»óÀº ¾Æ·¡¿Í °°ÀÌ ¼¼Æõ˴ϴÙ. Action Bar´Â Dark ±×¸®°í ÅؽºÆ®°¡ ³ëÃâµÇ´Â ȸéÀº Light ÀÔ´Ï´Ù.
±×¸®°í manifests Æú´õ¿¡¼ AndroidManifest.xml ÆÄÀÏÀ» ¿ÀÇÂÇϸé />
±×¸®°í manifests Æú´õ¿¡¼ AndroidManifest.xml ÆÄÀÏÀ» ¿ÀÇÂÇϸé style/AppTheme ¸¦ android:theme ·Î Á¤ÇÏ°í Àִµ¥ style.xml ÆÄÀÏÀ» ¿¾î º¸¸é
ÇØ´ç ¼Ó¼ºÀÌ ¼³Á¤µÇ¾î ÀÖÀ½À» È®ÀÎ ÇÒ ¼ö ÀÖ´Ù.
manifests/AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
res Æú´õ¿¡¼ styles.xml ÆÄÀÏÀ» ¿ÀÇÂÇÏ¸é ¾Æ·¡¿Í °°ÀÌ Á¤ÀÇ µÇ¾î ÀÖ´Ù.
res/value/styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
App Theme ¼Ó¼º¿¡ ´ëÇÑ °ªÀ¸·Î Theme.AppCompat.Light.DarkActionBar °¡ Á¤ÀÇ µÇ¾î ÀÖ´Â °ÍÀ» È®ÀÎ ÇÒ ¼ö ÀÖ´Ù.
Theme.AppCompat : Àüü Theme ¸¦ Dark ·Î ¼³Á¤
Theme.AppCompat.Light : Àüü Theme ¸¦ Light ·Î ¼³Á¤
Theme.AppCompat.Light.DarkActionBar : Action Bar ´Â Dark ·Î View ´Â Light ·Î ¼³Á¤
Theme.AppCompat.Light.DarkActionBar ¸¦ À§¿Í °°Àº °ªÀ¸·Î º¯°æÇÏ¿© ½ÇÇàÇÏ¿© º¸¸é ¾Æ·¡¿Í °°ÀÌ º¯°æµÈ Theme ·Î Àû¿ëµÇ¾î ¾ÛÀÌ ½ÇÇà µÈ´Ù.
Theme.AppCompat Àû¿ë½Ã ȸé
±×¸®°í manifests Æú´õÀÇ AndroidManifest.xml ÆÄÀÏÀ» ¿ÀÇÂÇÏ°í ¾Æ·¡¿Í °°ÀÌ ¼öÁ¤ÇÑ´Ù.
manifests/AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" -> android:theme="@android:style/Theme.Holo" >
</div>
À§¿Í °°ÀÌ ¼Ó¼ºÀ» º¯°æ ÈÄ ½ÇÇàÇϸé Dark Theme °¡ Àû¿ëµÈ ¾ÛÀÌ ½ÇÇà µÇ´Â °ÍÀ» È®ÀÎ ÇÒ ¼ö ÀÖ½À´Ï´Ù.
ÀÌ¿Ü¿¡ Action Bar ¸¦ Ä¿½ºÅ͸¶ÀÌ¡ ÇÏ¿© Àû¿ëÇÒ ¼öµµ ÀÖ½À´Ï´Ù.
res/values µð·ºÅ丮¿¡ themes.xml ÆÄÀÏÀ» »õ·Î »ý¼º ÇÏ°í ¾Æ·¡ Äڵ带 ÀÔ·Â ÇÕ´Ï´Ù.
res/values/themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="@android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<!-- ActionBar />
±×¸®°í manifests Æú´õÀÇ AndroidManifest.xml ÆÄÀÏÀ» ¿ÀÇÂÇÏ°í ¾Æ·¡¿Í °°ÀÌ ¼öÁ¤ÇÑ´Ù.
manifests/AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" -> android:theme="@android:style/Theme.Holo" >
</div>
À§¿Í °°ÀÌ ¼Ó¼ºÀ» º¯°æ ÈÄ ½ÇÇàÇϸé Dark Theme °¡ Àû¿ëµÈ ¾ÛÀÌ ½ÇÇà µÇ´Â °ÍÀ» È®ÀÎ ÇÒ ¼ö ÀÖ½À´Ï´Ù.
ÀÌ¿Ü¿¡ Action Bar ¸¦ Ä¿½ºÅ͸¶ÀÌ¡ ÇÏ¿© Àû¿ëÇÒ ¼öµµ ÀÖ½À´Ï´Ù.
res/values µð·ºÅ丮¿¡ themes.xml ÆÄÀÏÀ» »õ·Î »ý¼º ÇÏ°í ¾Æ·¡ Äڵ带 ÀÔ·Â ÇÕ´Ï´Ù.
res/values/themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="@android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#FF0000</item>
</style>
</resources>
À§ÀÇ Äڵ带 º¸¸é CustomActionBarTheme ¸¦ »ý¼ºÇÏ°í Àִµ¥ ±âº» Theme ¸¦ Á¤ÀÇÇÏ°í actionBarStyle ¼Ó¼ºÀ» Ãß°¡ ÇÏ¿© MyActionBar ÀÇ
¼Ó¼ºÀ» ÂüÁ¶ ÇÏ´Â °ÍÀ» º¼ ¼ö ÀÖ´Ù. MyActionBar ¿¡¼´Â background ÀÇ »ö»óÀ» º¯°æ ÇÑ´Ù.
AndroidManifest.xml ÆÄÀÏÀ» ¿ÀÇÂÇÏ¿© ¾Æ·¡¿Í °°ÀÌ Theme ¸¦ º¯°æ ÇÕ´Ï´Ù.
manifests/AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/CustomActionBarTheme>
¾ÛÀ» ½ÇÇà ÇÏ¸é ¾Æ·¡¿Í °°ÀÌ Action Bar ÀÇ Background »ö»óÀÌ º¯°æµÈ °ÍÀ» È®ÀÎ ÇÒ ¼ö ÀÖ´Ù.
Action Bar ÀÇ Text »ö»óÀ» º¯°æÇÒ ¼öµµ ÀÖ´Ù. res/values/themes.xml ÆÄÀÏ¿¡ ¾Æ·¡¿Í °°ÀÌ ±½Àº ÄÚµå ºÎºÐÀ» Ãß°¡ ÇÕ´Ï´Ù.
res/values/themes.xml
<style name="MyActionBar"
parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#FF0000</item>
<item name="android:titleTextStyle">@style/MyActionBarTitleText</item>
</style>
<style name="MyActionBarTitleText"
parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@color/actionbar_text</item>
</style>
Ãß°¡µÈ ÄÚµå´Â MyActionBarTitleText ¼Ó¼ºÀÌ Ãß°¡ µÇ¾ú°í ÇØ´ç ¼Ó¼º¿¡´Â ActionBar ÀÇ textColor ¸¦ @color/actionbar_text ¸¦ °ªÀ¸·Î ÇÏ°í ÀÖ½À´Ï´Ù.
ÀÌÁ¦ res/values µð·ºÅ丮¿¡ color.xml À̶ó´Â ÆÄÀÏÀ» »ý¼º ÇÕ´Ï´Ù.
res/values/color.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="actionbar_text">#FF1493</color>
</resources>
¾Æ·¡ ¼Ò½º´Â themes.xml ¿¡¼ »ç¿ëµÉ¼ö ÀÖ´Â ¿¹Á¦µéÀ» ³ÖÀº ¼Ò½º ÀÔ´Ï´Ù.
¿©·¯°¡ÁöÀÇ />
¾Æ·¡ ¼Ò½º´Â themes.xml ¿¡¼ »ç¿ëµÉ¼ö ÀÖ´Â ¿¹Á¦µéÀ» ³ÖÀº ¼Ò½º ÀÔ´Ï´Ù.
¿©·¯°¡ÁöÀÇ styleÀ» º¯°æÇÒ ¼ö ÀÖÀ¸´Ï Âü°íÇϽñ⠹ٶø´Ï´Ù.
res/values/themes.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CustomActionBarTheme"
parent="@style/Theme.AppCompat">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">@style/MyActionBarTabText</item>
<item name="android:actionMenuTextColor">@color/actionbar_text</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/MyActionBar</item>
<item name="actionBarTabTextStyle">@style/MyActionBarTabText</item>
<item name="actionMenuTextColor">@color/actionbar_text</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="@style/Widget.AppCompat.ActionBar">
<item name="android:titleTextStyle">@style/MyActionBarTitleText</item>
<!-- Support library compatibility -->
<item name="titleTextStyle">@style/MyActionBarTitleText</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText"
parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/actionbar_text</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>
<!-- ActionBar tabs text -->
<style name="MyActionBarTabText"
parent="@style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">@color/actionbar_text</item>
<item name="android:background">@drawable/popup_background</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>
</resources>
À§ themes.xml ÆÄÀÏ¿¡¼ Áß¿äÇÑ Á¡Àº ActionBarÀÇ Tab ºÎºÐµµ ½ºÅ¸Àϸµ ÇÒ ¼ö ÀÖ½À´Ï´Ù. actionBarTabTextStyle ¼Ó¼ºÀÌ Ãß°¡ µÇ¾ú°í style µµ Ãß°¡µÇ¾ú½À´Ï´Ù.
Tab ¸Þ´ºÀÇ ÅؽºÆ® »ö»óÀ̳ª, ¹é±×¶ó¿îµå À̹ÌÁö¸¦ Ãß°¡ÇÒ ¼ö ÀÖ°Ô µÇ¾î ÀÖ½À´Ï´Ù.
³ªÁß¿¡ ÇÊ¿äÇÒ ¶§ Âü°íÇؼ °³¹ßÇØ º¸½Ã±â ¹Ù¶ø´Ï´Ù.