가끔 어떤 갑님은 액션바에 메뉴아이템 하나만 표시하고, 나머지는 아예 없는 것처럼 만들어 달라고 하는데, 매번 찾기 귀찮아서 적어둔다.
액션바를 달면 이런 식으로 그림자가 생긴다.
<android.support.design.widget.AppBarLayout android:id="@+id/app_bar" android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/colorPrimary" android:minHeight="?attr/actionBarSize" app:contentInsetStart="0dp" app:contentInsetStartWithNavigation="0dp" app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> </android.support.design.widget.AppBarLayout>
물론 이런 식으로 elevation을 넣으면 되지만, 때에 따라서는 코드에서 넣어야 할 때도 있다.
<android.support.design.widget.AppBarLayout android:id="@+id/app_bar" android:layout_width="match_parent" android:layout_height="wrap_content" app:elevation="0dp">
actionbar remove shadow
같은 단어로 검색하면 아래의 코드들이 나오는데, 다 안된다.
getSupportActionBar().setElevation(0f);
AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.app_bar); appBarLayout.setElevation(0f);
ViewCompat.setElevation(appBarLayout, 0);
그나마 찾은 되는 코드는 이 것 뿐이었다. (min sdk >= 21)
AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.app_bar); StateListAnimator stateListAnimator = new StateListAnimator(); stateListAnimator.addState(new int[0], ObjectAnimator.ofFloat(appBarLayout, "elevation", 0)); appBarLayout.setStateListAnimator(stateListAnimator);
사실상 min sdk가 21보다 낮다면, 아예 액션바를 숨기고 액션바처럼 보이는 뷰를 만드는 게 나을 것 같다.