嗨,这里有新的Android开发人员。
我正在尝试让我的操作栏透明/半透明。我已经改变了我的观点背景,看看我是否正确地做到了这一点。
我在这里看过很多线程,但没有一个对我有用。
我尝试为我的操作栏制作自定义样式并使用:<item name="android:background">#55CC00CC</item>
但这不起作用。我得到了纯白色作为背景。
我也尝试在我的活动中获取ActionBar实例并执行actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#55CC00CC")));
而我得到了这个:
我正在尝试查看是否可以在我的活动中以编程方式执行此操作。一些代码要看:
styles.xml:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:windowActionBarOverlay">true</item>
</style>
</resources>
MainActivity.java:
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
super.onCreate(savedInstanceState);
ActionBar actionBar = getSupportActionBar();
setContentView(R.layout.activity_main);
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#55CC00CC")));
}
我错过了一些明显的东西吗?提前谢谢。
答案 0 :(得分:0)
如果您的目标是最低API级别11,则可以通过定义自定义样式来更改ActionBar的背景颜色,如下所示:
<resources>
<style name="ActionBarCustomTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">ANY_HEX_COLOR_CODE</item>
</style>
并将“ActionBarCustomTheme”设置为应用程序/活动的主题。 这样做......
答案 1 :(得分:0)
如yshanak
所述,将我的主题更改为Holo而不是AppCompat可以解决问题。
使用Holo时崩溃的人:
ActionBarActivity
需要使用AppCompat主题,所以我只是通过扩展Activity
来修复我的。
答案 2 :(得分:0)
刚刚解决了同样的问题
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp"
>
<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.AppBarOverlay"/>
</android.support.design.widget.AppBarLayout>
和java方面部分
mToolbar.getBackground().setColorFilter(getResources().getColor(android.R.color.white), PorterDuff.Mode.SRC_ATOP);
mToolbar.getBackground().setAlpha(0);
mToolbarLayout.getBackground().setAlpha(0);