programing

투명한 액션 바 : 사용자 정의 탭 색상

nasanasas 2020. 11. 26. 08:26
반응형

투명한 액션 바 : 사용자 정의 탭 색상


투명한 탭이있는 ActionBar를 만들고 싶습니다 #3b000000. 이와 비슷하지만 ActionBar 아래에 탭이 있습니다.

여기에 이미지 설명 입력

이것은 styles.xml에서 사용중인 코드입니다.

<style name="Theme.MyTheme" parent="@style/Theme.Sherlock.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/ActionBar</item>
    <item name="windowActionBarOverlay">true</item>
    <item name="android:windowActionBarOverlay">true</item>
    <item name="actionBarStyle">@style/ActionBar</item>
</style>

<style name="ActionBar" parent="@style/Widget.Sherlock.Light.ActionBar">
    <item name="android:background">@color/actionbar</item>
    <item name="background">@color/actionbar</item>
    <item name="android:actionBarTabStyle">@style/ActionBarTabStyle</item>
    <item name="actionBarTabStyle">@style/ActionBarTabStyle</item>
</style>

<style name="ActionBarTabStyle" parent="@style/Widget.Sherlock.ActionBar.TabView">
    <item name="background">@color/actionbar_tabs</item>
    <item name="android:background">@color/actionbar_tabs</item>
</style>

무슨 일이 일어나는지, ActionBar 자체 투명한 배경색을 보여 주지만 탭은 완전히 투명합니다 (색상이 보이지 않음).

어떻게 해결할 수 있습니까?


전화 setStackedBackgroundDrawable()ActionBar:

getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#330000ff")));
actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#550000ff")));

이렇게하면 다음과 같은 결과가 생성됩니다 (예 : 임의의 아이콘과 탭, 효과를 강조하는 두 가지 다른 푸른 배경색).

여기에 이미지 설명 입력

(새로 고침 아이콘은 약간의 투명도를 제공하는 기본 아이콘입니다. 다른 아이콘은 #FFFFFFFF 색상, 즉 투명도가없는 사용자 정의 테스트 아이콘입니다.)


프로젝트에서이 작업을 수행했으며 스타일은 다음과 같습니다.

<style name="AppTheme" parent="android:Theme.Holo">
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:actionBarStyle">@style/action_bar_theme</item>
    <item name="android:actionMenuTextColor">#fff</item>
</style>

<style name="action_bar_theme" parent="@android:style/Widget.Holo.ActionBar">
    <item name="android:background">#b3000000</item>
    <item name="android:titleTextStyle">@style/action_bar_text</item>
</style>

이 기사 에서 언급했듯이 다음 사용자 정의 테마를 사용하면 완벽하게 작동합니다.

<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
           parent="@android:style/Theme.Holo">
        <item name="android:windowActionBarOverlay">true</item>
    </style>
</resources>

약간의 색조를 적용하기 위해 Gunnar의 대답은 방법을 보여줍니다.

ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#330000ff")));
actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#550000ff")));

완전히 투명한 Actionbar에 대한 코드는 다음과 같습니다.

<!-- Base application theme. -->
<style name="TransparentTheme" parent="android:Theme.Holo.Light">
    <!-- Customize your theme here. -->
    <item name="android:windowBackground">@null</item>
    <item name="android:actionBarStyle">@style/ActionBarStyle.Transparent</item>
    <item name="android:windowActionBarOverlay">true</item>
</style>

<style name="ActionBarStyle.Transparent" parent="android:Widget.ActionBar">
    <item name="android:background">@null</item>
    <item name="android:displayOptions">showHome|showTitle</item>
    <item name="android:titleTextStyle">@style/ActionBarStyle.Transparent.TitleTextStyle</item>
</style>

<style name="ActionBarStyle.Transparent.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">@android:color/white</item>
</style>

여기에 이미지 설명 입력


             getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);//or add in style.xml
             ActionBar actionBar = getActionBar();

             ColorDrawable newColor = new ColorDrawable(getResources().getColor(R.color.action_bar_color));//your color from res
             newColor.setAlpha(128);//from 0(0%) to 256(100%)
             getActionBar().setBackgroundDrawable(newColor);

style.xml

<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
           parent="@android:style/Theme.Holo">
        <item name="android:windowActionBarOverlay">true</item>
    </style>
</resources>

테마 작업 표시 줄을 배경 이미지 또는 색상으로 투명하게 설정하려면 구현하는 가장 좋고 쉬운 방법이 표시되어야합니다.

        actionBar.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(activity, android.R.color.transparent)));


    ImageView image = new ImageView(this);
    image.setTag(R.string.decore_view);
    image.setAdjustViewBounds(true);
    image.setScaleType(ImageView.ScaleType.CENTER_CROP);
    image.setLayoutParams(new ViewGroup.LayoutParams(-1, -1));
    image.setImageResource(R.drawable.home_bg);
    ((ViewGroup)((ViewGroup)getWindow().getDecorView())).addView(image, 0);

ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

그것은 나를 위해 잘 작동했다


이것은 ActionBar투명하게 만드는 제 경우에 잘 작동합니다 .

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#330000ff")));
getSupportActionBar().setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#550000ff")));

<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="android:actionBarTabBarStyle">@style/MyActionBarTabBar</item>
    <item name="android:windowActionBarOverlay">true</item>
</style>

<style name="MyActionBar"
    parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
    <item name="android:background">@color/actionbar</item>
    <item name="android:backgroundStacked">@color/tabbar</item>


</style>

투명한 색상 / 액션 바 및 색상 / 탭바 색상 값

참고 URL : https://stackoverflow.com/questions/13726214/transparent-actionbar-custom-tabcolor

반응형