안드로이드 상태바 투명 처리

|

안드로이드 상태바를 투명하게 만드는 방법입니다.

대충 안드로이드 상태바는 다음과 같은 형태로 표현할 수 있습니다.

1) 아무런 설정을 안 해줬을 때의 기본적인 상태바

image

2) 색상을 입힌 상태바

image

3) 투명 처리를 한 상태바

image

과거에는 완전히 투명한 상태바도 표현할 수 있었는데, 지금은 반투명 상태로 표현되고 있습니다.


일단, 반투명 상태의 상태바는 다음과 같은 테마를 적용하여 구현할 수 있습니다.


styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
  <!-- Customize your theme here. -->
  <item name="colorPrimary">@color/colorPrimary</item>
  <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
  <item name="colorAccent">@color/colorAccent</item>
  <item name="android:windowDrawsSystemBarBackgrounds">true</item>
  <item name="android:statusBarColor">@color/transparent</item>
  <item name="android:windowTranslucentStatus">true</item>

</style>


때에 따라서 반투명 상태보다는 색상을 입힌 상태바가 더 좋을 때가 있습니다. 상태바의 색상을 primaryColor와 똑같이 지정하면 투명 상태처럼 보이기도 합니다. 그럴 때는

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
  <!-- Customize your theme here. -->
  <item name="colorPrimary">@color/colorPrimary</item>
  <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
  <item name="colorAccent">@color/colorAccent</item>
  <item name="android:windowDrawsSystemBarBackgrounds">true</item>
  <item name="android:statusBarColor">@color/colorPrimary</item>
  <item name="android:windowTranslucentStatus">false</item>

</style>

와 같이 지정해주면 됩니다.

7.0(Nougat) 에서 Dialog 들의 버튼들이 보이지 않는 현상

|

안드로이드 7.0 Nougat에서 다음 이미지와 같이 Dialog들의 버튼이 사라져 버리는 현상이 있습니다.

image

AlertDialog 뿐만 아니라 PickerDialog 들도 마찬가지 현상이 발생했습니다.

image

기존에 잘 되던 코드였는데, 갑자기 안드로이드 7.0을 올린 사람들에게 이런 반응이 나와서 찾아보니 7.0 부터는 Dialog에 테마(theme)를 적용해야 하는 정책이 생겼다고 합니다. 테마를 적용하지 않은 기존의 Dialog 들의 버튼은 투명 처리되어 보이지 않습는다. (투명 처리만 되어있어서 해당 버튼이 있는 위치를 누르면 동작은 한다고 합니다;;)  갑자기 왜 이런 하위 호환성을 무시해버린 정책을 만들었는지 모르겠지만, 일단은 해결법을 알아보도록 하겠습니다.


먼저 Dialog용 테마를 하나 만듭니다.

styles.xml

<style name="AlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
  <item name="colorPrimary">@color/colorPrimary</item>
  <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
  <item name="colorAccent">@color/colorAccent</item>
  <item name="borderlessButtonStyle">@style/Widget.AppCompat.Button.Borderless.Colored</item>
</style>


그리고 기존에 AlertDialog를 작성하던 코드가 다음과 같았다면

기존 코드

mAlertDialog = new AlertDialog.Builder(getActivity())
    .setTitle("쿠폰 구입")
    .setMessage("'" + item.name + "'를 정말로 구매하시겠습니까? 포인트가 " + item.price + " 원 차감됩니다.")

다음과 같이 수정합니다.


수정된 코드

mAlertDialog = new AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme)
    .setTitle("쿠폰 구입")
    .setMessage("'" + item.name + "'를 정말로 구매하시겠습니까? 포인트가 " + item.price + " 원 차감됩니다.")

현재 Application Version을 코드에서 사용하기

|

안드로이드 App을 개발할 때 App Version을 소스 코드내에서 활용하고 싶을 때가 있습니다.

Eclipse의 경우에는 App Version이 manifest.xml 파일 내에 정의되어 있는데, Android Studio에서는 build.gradle 내에 버전이 입력되어 있습니다.


build.gradle

App Version은 build.gradle 내에 다음과 같이 설정됩니다.

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        multiDexEnabled true
        applicationId "com.lnc.cuppadata"
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 10
        versionName "0.10"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    ...



그리고 안드로이드 소스내에서 App Version을 가져오는 코드는 다음과 같습니다.

소스 코드

private String getAppVersion() {
  try {
    PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(
        getActivity().getPackageName(), 0);

    if(pInfo != null) {
      return pInfo.versionName;
    }
  } catch(Exception e) {
    e.printStackTrace();
  }

  return "";
}

터미널에서 tree 명령어 사용하기

|

tree 명령어

tree는 폴더 구조를 시각적으로 알아보기 쉽게 트리 형태로 보여주는 명령어입니다. 불행히도 Mac에는 이 명령어를 제공하지 않습니다. 그래서 Homebrew를 이용해서 tree를 설치해보도록 하겠습니다.

먼저 Homebrew를 설치해야 합니다.

tree 설치는 다음 명령어를 이용해서 진행할 수 있습니다.

brew install tree

설치 후 tree 명령어를 수행하면 다음과 같이 폴더 구조를 트리 형태로 표현해줍니다.

image

Homebrew 설치하기

|

Homebrew

Mac에서 홈브류(Homebrew)는 패키지 매니저(Package Manager)로 생각하면 됩니다. ruby로 개발되어졌으며, 애플에서 제공하지는 않지만 유용한 프로그램들을 손쉽게 다운로드하고 설치할 수 있게 해주고 있습니다.

image


설치 방법

Homebrew를 설치하기 위해서는 먼저 CLD(Command Line Developer Tool)를 설치해야 합니다. 터미널에서 다음 명령어를 입력하면 됩니다.

xcode-select –install

그 다음에는 다음 명령어를 이용하여 Homebrew를 설치합니다.

ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

최신 설치 명령어는 여기에서 확인할 수 있습니다.

설치를 시작하면, ‘Press RETURN to continue or any other key to abort’ 라는 메세지가 나오고 Return 키 를 누르면 설치가 시작됩니다.