gpt4 book ai didi

Android ActionBar with Sliding Tabs - 如何去除阴影效果

转载 作者:行者123 更新时间:2023-11-30 02:01:57 24 4
gpt4 key购买 nike

我创建了一个屏幕,其中包含一个 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、自定义您的应用主题:

<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、自定义您的工具栏:

<?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);

关于Android ActionBar with Sliding Tabs - 如何去除阴影效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31323152/

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