2016-09-02 2 views
3

anot DSL로 kotlin을 테스트하려면 kotlin 플러그인 (1.0.3)과 최신 anko 라이브러리 (0.9.3)를 사용하여 마지막 android studio ide (2.1.3)에서 새로운 proyect를 시작하기로 결정했습니다.상태 표시 줄이 투명하지 않고 흰색이 아닙니다

기본 proyect Navigation Drawer Activity를 사용 했으므로 main xml을 anko로 변환해야했습니다.

은 XML입니다 :

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="start"> 

    <android.support.design.widget.CoordinatorLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <android.support.design.widget.AppBarLayout 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent" 
      android:theme="@style/AppTheme.AppBarOverlay"> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:background="?attr/colorPrimary" 
       app:popupTheme="@style/AppTheme.PopupOverlay" /> 

     </android.support.design.widget.AppBarLayout> 

     <RelativeLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      xmlns:app="http://schemas.android.com/apk/res-auto" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:paddingLeft="@dimen/activity_horizontal_margin" 
      android:paddingRight="@dimen/activity_horizontal_margin" 
      android:paddingTop="@dimen/activity_vertical_margin" 
      android:paddingBottom="@dimen/activity_vertical_margin" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior" > 

      <TextView 
       android:text="Hello World!" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 

     </RelativeLayout> 

    </android.support.design.widget.CoordinatorLayout> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/nav_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:fitsSystemWindows="true" 
     app:headerLayout="@layout/nav_header_main" 
     app:menu="@menu/activity_main_drawer" /> 

</android.support.v4.widget.DrawerLayout> 

그리고 당신은 여기에서 볼 수 있듯이 그것이 완벽하게 작동된다 ANKO와 [xml]

을,이 코드를 얻기는 XML에서 모든 세부 사항을 복사하려고 :

class MainActivityUi: AnkoComponent<MainActivity> { 
    override fun createView(ui: AnkoContext<MainActivity>) = with(ui) { 

     drawerLayout { 
      id = R.id.drawer_layout 
      fitsSystemWindows = true 

      coordinatorLayout { 

       appBarLayout(R.style.AppTheme_AppBarOverlay) { 

        toolbar { 
         id = R.id.toolbar 
         backgroundColor = colorAttr(R.attr.colorPrimary) 
         popupTheme = R.style.AppTheme_PopupOverlay 
        }.lparams(height=dimenAttr(R.attr.actionBarSize),width=matchParent) 

       }.lparams(width=matchParent) 

       relativeLayout { 
        padding = dip(16) 

        textView("Hello World!") 

       }.lparams(height=matchParent,width=matchParent) { 
        behavior = AppBarLayout.ScrollingViewBehavior() 
       } 

      }.lparams(height=matchParent,width=matchParent) 

      navigationView { 
       id = R.id.nav_view 
       inflateHeaderView(R.layout.nav_header_main) 
       inflateMenu(R.menu.activity_main_drawer) 

      }.lparams(height=matchParent) { 
       gravity = Gravity.START 
       fitsSystemWindows = true 
      } 
     } 
    } 
} 

그리고 대신에, 나는이 흰색 상태 표시 얻고있다 : anko

MainActivity에서 변경된 사항은 setContentView (R.layout.activity_main)를 MainActivityUi.setContentView (this)로 변경 한 것뿐입니다.

그래서 내 질문은 왜 그들이 같은보기와 레이아웃 일 때입니까? 어떻게 해결할 수 있습니까?

EDIT : Android Studio에서 새 proyect를 선택한 다음 DrawerNavigationActivity를 선택할 때 생성되는 기본 proyect를 사용하고 있습니다. setContentView에서 xml 뷰를 표시하도록 선택하면 상태 표시 줄이 파란색 (첫 번째 스크린 샷)이지만 anko의 뷰를 표시하도록 선택하면 흰색 상태 표시 줄이 나타납니다. 두 경우 모두

, 나는 등 같은 주제, 색상을 사용하고, 그리고 XML 레이아웃을 사용하는 경우, 모든 것이 완벽하게 작동한다, 그래서 당신은 상태가 잘못 생각하고

+0

fitsSystemWindows = true를 appBarLayout으로 설정하려고 했습니까? – Stepango

+0

정확히 같은 문제가 여기에 있는데, 나는 '서랍'을 넣었습니다. 상태 표시 줄에는 흰색 배경이있었습니다. idk,하지만 xml은 아주 잘 작동합니다. – MewX

답변

0

ANKO의 문제가 될 수 있어야합니다 기본값은 transparent입니다. 안드로이드 개발자 참조 찍은 이미지

enter image description here

따르면

. 확인 : https://developer.android.com/training/material/theme.html

상태 표시 줄 색상은 colorPrimaryDarkvalues 폴더에 colors.xml 또는 styles.xml에 정의에 따라 달라집니다, 그래서 투명 아니다.

상태 표시 줄의 투명도는 문제가 아니지만 Android 응용 프로그램에서 테마를 사용하는 것에 대한 충분한 지식이 없습니다.

편집 : 변경 상태 표시 줄 색상 (자바) :

Window window = activity.getWindow(); 

// clear FLAG_TRANSLUCENT_STATUS flag: 
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 

// add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window 
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); 

// finally change the color 
window.setStatusBarColor(activity.getResources().getColor(R.color.my_statusbar_color)); 

또는

public void setStatusBarColor(View statusBar,int color){ 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 
      Window w = getWindow(); 
      w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 
      //status bar height 
      int actionBarHeight = getActionBarHeight(); 
      int statusBarHeight = getStatusBarHeight(); 
      //action bar height 
      statusBar.getLayoutParams().height = actionBarHeight + statusBarHeight; 
      statusBar.setBackgroundColor(color); 
    } 
} 

그것이

+0

Android Studio의 새 proyect에서 기본 예제 proyect "Navigation Drawer Activity"를 사용하고 있기 때문에 테마가 문제라고 생각하지 않습니다. setContentView (R.layout.activity_main)를 사용하여 앱을 컴파일하면 xml의 뷰 (첫 번째 스크린 샷)가로드되고 대신 MainActivityUi(), setContentView (this), anko의 뷰가로드됩니다. 로드 된 및 두 번째 그림처럼 보여 그래서 테마가 괜찮을 것 같다 – yaymalaga

+0

위의 코드를 확인한 위의 코드를 확인했습니다 – piotrek1543

+0

어쨌든 도움 주셔서 감사하지만 내 질문을 편집했습니다 투명도가 작동합니다. 문제가 anko의 DSL과 관련이 있습니다. – yaymalaga

0

도움이 될 것입니다 희망 그것은 당신의 상태 표시 줄의 색상 문제가되지 않습니다.
내가 틀렸다고 정정하면 Cyanogenmod OS 13을 사용하고 있다고 생각합니다.0 버전을 배터리 기호 모양으로 표시합니다. 테마 섹션의 기본 테마로 다시 전환하십시오. 그런 다음 colors.xml 파일에 문제가 지속되면 다시보고하십시오.


이 링크는 Kotlin 반투명 상태 표시 줄 문제를 참조하십시오.
https://github.com/fython/MaterialStatusBarCompat

+0

내 화면보기 질문의 편집 – yaymalaga

+0

상태 표시 줄 반투명 문제에 대한 Kotlin 플러그인 샘플에 대한 편집 된 답변을 참조하십시오. –

1

시도에서 onCreate() 내부

window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)

을 할

Reference

EDIT 나를 위해 일한

: 또한 내 코드

drawerLayout { 
    lparams(width = matchParent, height = matchParent) 

    coordinatorLayout { 
    setPadding(0, dip(24), 0, 0) 

    appBarLayout { 
     toolbar { 
      backgroundColor = primaryColor 
      setTitleTextColor(primaryColorText) 
     }.lparams(width = matchParent, height = dip(toolbar_size)) 

    }.lparams(width = matchParent, height = dip(toolbar_size)) 

    }.lparams(width = matchParent, height = matchParent) 

    navigationView { 

    }.lparams(width = dip(302), height = matchParent) { 
    gravity = Gravity.START 
    } 
} 
관련 문제