【问题标题】:Remove shadow and line below action bar using support library使用支持库删除操作栏下方的阴影和线条
【发布时间】:2016-01-29 19:32:28
【问题描述】:

由于 ActionBar.TabListener 现在已被弃用,我已按照本教程设置 Material Design 滑动选项卡:

http://www.android4devs.com/2015/01/how-to-make-material-design-sliding-tabs.html

它有效,但我试图删除操作栏下方的线条+阴影但没有成功。即使设置 getSupportActionBar().setElevation(0);正如其他线程中所建议的那样。

我知道如果我将活动的自定义样式设置为 @style/Theme.AppCompat 而不是 @style/Theme.AppCompat.Light (实际配置)线条+阴影消失,但选项菜单和其他共享这种风格的活动变暗..我不想要它。

所以我正在尝试找到一种方法来删除线条+阴影并将主要样式保持为“Light”。

图片:

MainActivity (OnCreate)

public class MainActivity extends AppCompatActivity {

// Declaring Your View and Variables

Toolbar toolbar;
ViewPager pager;
ViewPagerAdapter adapter;
SlidingTabLayout tabs;
CharSequence Titles[]={"1","2","3","4"};
int Numboftabs =4;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getSupportActionBar().setElevation(0);
    setContentView(R.layout.activity_main);

    //
    // Creating The Toolbar and setting it as the Toolbar for the activity

    toolbar = (Toolbar) findViewById(R.id.tool_bar);
    //setSupportActionBar(toolbar);

    // Creating The ViewPagerAdapter and Passing Fragment Manager, Titles fot the Tabs and Number Of Tabs.
    adapter =  new ViewPagerAdapter(getSupportFragmentManager(),Titles,Numboftabs);

    // Assigning ViewPager View and setting the adapter
    pager = (ViewPager) findViewById(R.id.pager);
    pager.setAdapter(adapter);

    // Assiging the Sliding Tab Layout View
    tabs = (SlidingTabLayout) findViewById(R.id.tabs);
    tabs.setDistributeEvenly(true); // To make the Tabs Fixed set this true, This makes the tabs Space Evenly in Available width

    // Setting Custom Color for the Scroll bar indicator of the Tab View
    tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
        @Override
        public int getIndicatorColor(int position) {
            return getResources().getColor(R.color.darkgreen);
        }
    });

    // Setting the ViewPager For the SlidingTabsLayout
    tabs.setViewPager(pager);



}

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<include
    android:id="@+id/tool_bar"
    layout="@layout/tool_bar"
    android:layout_height="10dp"
    android:layout_width="match_parent"
    android:layout_gravity="right" />

<com.myapp.library.sliding_tab.SlidingTabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:elevation="0dp"
    android:theme="@style/Theme.AppCompat"
    android:background="@color/orange"/>

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:layout_weight="1"
    android:textColor="@color/black"
    android:background="@color/white">
</android.support.v4.view.ViewPager>

</LinearLayout>

tool_bar.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="@color/orange"
android:elevation="0dp"
android:theme="@style/Base.ThemeOverlay.AppCompat.Light"
xmlns:android="http://schemas.android.com/apk/res/android" />

styles.xml

<resources>

<style name="MyCustomTheme" parent="@style/Theme.AppCompat.Light">
    <item name="android:actionBarStyle">@style/MyActionBarTheme</item>
    <item name="android:actionBarTabBarStyle">@style/MyActionBarTabTheme</item>

    <item name="actionBarStyle">@style/MyActionBarTheme</item>
    <item name="actionBarTabBarStyle">@style/MyActionBarTabTheme</item>
</style>

<style name="MyActionBarTheme" parent="@style/Widget.AppCompat.Light.ActionBar">
    <item name="android:background">@color/orange</item>

    <item name="background">@color/orange</item>
</style>
<style name="MyActionBarTabTheme" parent="@style/Widget.AppCompat.ActionBar.TabView">
    <item name="android:background">@color/orange</item>

    <item name="background">@color/orange</item>
</style>

</resources>

清单(仅主要活动)

<activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/MyCustomTheme">
</activity>

【问题讨论】:

标签: android android-actionbar material-design android-appcompat


【解决方案1】:

在 AppBarLayout 中添加 app:elevation="0dp" 用于在 App Bar 中隐藏阴影。

here得到解决方案:

【讨论】:

    猜你喜欢
    • 2012-08-28
    • 1970-01-01
    • 2015-10-08
    • 1970-01-01
    • 2013-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多