gpt4 book ai didi

android - 使用支持库删除操作栏下方的阴影和线条

转载 作者:太空宇宙 更新时间:2023-11-03 13:17:39 25 4
gpt4 key购买 nike

由于 ActionBar.TabListener 现已弃用,我已按照本教程设置 Material Design 滑动标签:

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

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

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

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

图片: enter image description here

主 Activity (创建时)

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>

工具栏.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" />

样式.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>

list (仅主要 Activity )

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

最佳答案

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

here得到解决方案:

关于android - 使用支持库删除操作栏下方的阴影和线条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33417949/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com