맞춤형 반투명 Android ActionBar
나는 상당히 사소한 질문이라고 생각했던 것에 대한 답을 찾기 위해 인터 웹 (예 : Android 문서, 여기에있는 답변 등)을 수색 해 왔습니다. Google Music 및 YouTube 의 것과 같은 반투명 작업 표시 줄을 어떻게 얻 습니까 (링크는 이미지 예시 임)?
비디오 콘텐츠가 전체 화면으로 표시되고 기본 제공 UI 구성 요소의 이점을 계속 활용하면서 작업 표시 줄에 의해 제한 / 푸시되지 않기를 원합니다. 분명히 완전한 사용자 정의보기를 사용할 수 있지만 가능하면 ActionBar를 활용하는 것이 좋습니다.
명백한
<activity
android:name="videoplayer"
android:theme="@android:style/Theme.Holo"
android:launchMode="singleTop"
android:configChanges="keyboardHidden|orientation"/>
활동
// Setup action bar
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
View customActionBarView = getLayoutInflater().inflate(R.layout.player_custom_action_bar, null);
actionBar.setCustomView(customActionBarView,
new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT,
R.dimen.action_bar_height));
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
메뉴
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/button1"
android:icon="@drawable/button1"
android:showAsAction="always"/>
<item
android:id="@+id/button2"
android:icon="@drawable/button2"
android:showAsAction="always"/>
</menu>
사용자 지정 ActionBar보기
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/custom_action_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:background="@color/TranslucentBlack">
<!--Home icon with arrow-->
<ImageView
android:id="@+id/home"
android:src="@drawable/home"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
<!--Another image-->
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:visibility="visible"/>
<!--Text if no image-->
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:visibility="gone"/>
<!--Title-->
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingLeft="20dp"
android:gravity="center_vertical"/>
</LinearLayout>
활동이 전체 화면으로 표시 되길 원하지만 여전히 작업 표시 줄을 표시하지만 알파가있는 경우 onCreate()
활동의 작업 표시 줄에 대한 오버레이 모드를 요청 해야합니다.
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
//getWindow().requestFeature(WindowCompat.FEATURE_ACTION_BAR_OVERLAY); << Use this for API 7+ (v7 support library)
Then after you call setContentView(..)
(since setContentView(..)
also initializes the actionbar next to setting the content) you can set a background drawable on your actionbar:
getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_bg));
which can be a shape drawable with an alpha put in res/drawable:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#BB000000" />
</shape>
You could also do this completely programatically by creating a ColorDrawable
:
getActionBar().setBackgroundDrawable(new ColorDrawable(Color.argb(128, 0, 0, 0)));
Otherwise ofcourse you can hide the actionbar completely; in that case you can set a custom theme on your activity in your manifest:
@android:style/Theme.NoTitleBar.Fullscreen
or programmatically by calling
getActionBar().hide();
In addition to the correct answer, if you are using AppcomatActivity, call supportRequestWindowFeature instead of
Old Version: getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
You want to use:
@Override
protected void onCreate(Bundle savedInstanceState) {
supportRequestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
super.onCreate(savedInstanceState);
}
I think you should be able to do this using the Window flag FEATURE_ACTION_BAR_OVERLAY
.
Before you call setContentView()
in your activity,
Call:
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
And it will use an overlaid ActionBar
instead of pushing down your window.
The above code is absolutely correct for making an action bar.
Instead of
getActionBar().setBackgroundDrawable(new ColorDrawable(Color.argb(128, 0, 0, 0)))
use
getActionBar().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
In this way, you will able to see the action bar fully transparent.
Here is how I got this to work:
1) Request for actionbar overlay programmatically by calling
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
this 'requestFeature()' must be requested from your activity 'onCreate()' method before calling for 'setContentView(R.layout.my_layout)':
2) set the actionbar color by calling setBackgroundDrawable()
like so:
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00212121")) );
this method requires either a reference to a drawable or you can also use a color parser to parse a hex color value (first 2 digits are used for alpha channel starting at #00 to #FF)
Note that I am using actionBarSherlok getSupportActionBar()
but this should work with any action bar.
If you still cant get this to work, try adding this to your theme style
<item name="windowActionBarOverlay">true</item>
<item name="android:actionBarStyle">@style/ActionBar.Transparent.Example</item>
<item name="android:windowActionBarOverlay">true</item>
I just like to share with you the steps I took to achieve this:
1) At the OnCreate of your activity,
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
then
getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
This is done before setContentView.
2) After setContentView, you can do the following
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.argb(0, 100, 181, 246)));
Where the alpha value of 0 means it is fully transparent.
ReferenceURL : https://stackoverflow.com/questions/6749261/custom-translucent-android-actionbar
'programing' 카테고리의 다른 글
Trac 대 Redmine (0) | 2021.01.17 |
---|---|
mysql에서 이름으로 그룹화하기 전에 날짜 및 시간으로 정렬 (0) | 2021.01.17 |
기본 마커를 제거하려면 어떻게합니까? (0) | 2021.01.17 |
패스는 jquery ajax에 헤더 매개 변수를 허용합니다. (0) | 2021.01.17 |
결과가없는 경우에도 값 반환 (0) | 2021.01.17 |