带有滑动标签的Android ActionBar - 如何删除阴影效果

时间:2015-07-09 16:25:25

标签: android android-layout

我创建了一个具有ActionBar和三个滑动标签的屏幕。我想让ActionBar和滑动标签具有相同的颜色,并且它们之间没有任何分界。但标签似乎有阴影效果。我想删除它。
我正在使用AppCompat.Light.DarkActionBar主题

image

屏幕的我的xml是

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.design.widget.TabLayout
        android:id="@+id/sliding_tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#77CB59"
        app:tabMode="scrollable" />

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="1"
        android:background="@android:color/white" />

</LinearLayout>

我的这个屏幕的java类

public class HomeScreen extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_screen);

        ActionBar actionBar = getSupportActionBar();
        actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#77CB59")));

        // Get the ViewPager and set it's PagerAdapter 
        ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
        viewPager.setAdapter(new MyFragmentPagerAdapter(getSupportFragmentManager(),
                HomeScreen.this));

        // Give the TabLayout the ViewPager
        TabLayout tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
        tabLayout.setupWithViewPager(viewPager);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_start_screen, menu);
        return true;
    }
}

1 个答案:

答案 0 :(得分:1)

1,自定义您的应用主题:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/app_color_primary</item>
    <item name="colorPrimaryDark">@color/app_color_primary_dark</item>
    <item name="colorAccent">@color/app_color_accent</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

2,自定义Toolbar

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:gravity="center"

    android:minHeight="?attr/actionBarSize"
    android:theme="@style/ToolbarStyle"
    android:title="@string/app_name">

</android.support.v7.widget.Toolbar>

3,将ActionBar替换为Toolbar

toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//If you want to set your new ActionBar
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setDisplayUseLogoEnabled(true);
getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
toolbar.setNavigationIcon(R.drawable.arrow_left);
toolbar.setLogo(R.mipmap.ic_launcher);