android 타이틀바 없애기, 색상 바꾸기

구잉·2021년 9월 8일

1. manifests.xml에서 style변경

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.test">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        >
    </application>
</manifest>

android:theme="@style/AppTheme" 대신
android:theme="@style/Theme.AppCompat.NoActionBar"
를 입력한다

다만,

You need to use a Theme.AppCompat theme (or descendant) with this activity

라는 에러가 뜬다면
AppCompatActivity를 상속받은 액티비티와 충돌이 발생하므로
AppCompatActivity를 Activity로 바꿔주면 해결된다


2. themes.xml 변경

themes.xml에 다음 코드를 추가한다

<!-- Customize your theme here. -->
<item name="windowActionBar">false</item> 
<item name="windowNoTitle">true</item>

3. 타이틀바 숨기기

onCreate에

getSupportActionBar().hide();

를 추가하면 해당 액티비티 타이틀바가 숨겨진다


(+타이틀바 색상바꾸기)
colors.xml

    <?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="black">#FF000000</color>
    <color name="white">#FFFFFFFF</color>
    <color name="orange">#FF9800</color>
</resources>

다음과 같은 형식으로 원하는 색을 추가 후에

themes.xml

<!-- Primary brand color. -->
        <item name="colorPrimary">@color/orange</item>
        <item name="colorPrimaryVariant">@color/black</item>
        <item name="colorOnPrimary">@color/white</item>

thems.xml에서 colorPrimary를 추가한 색으로 변경해주면 된다

profile
시작을 두려워하지말자

0개의 댓글