使用支持库

时间:2015-10-29 15:10:06

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

由于ActionBar.TabListener现已弃用,我已按照本教程设置了Material Design Sliding Tabs:

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"。

IMG: enter image description here

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>

1 个答案:

答案 0 :(得分:4)

在AppBarLayout中添加$scope.getExportFiles = function(fileKey) { // Build the URL we're wanting to fetch RESTCaller.getConfig({ method: "GET", url: baseSyncUrl + "/export", params: { fileKey: fileKey.toString() }, path: { version: "v1" } }).then(function(result) { // Assuming result is the URL of the download file. var fetchUrl = result.toString(); // Check if the current browser has support for Blob objects try { var blobSupport = !!new Blob; } catch (e) {} // If there is Blob support, use the angular-file-saver library // to download the file if (blobSupport) { $http .get(fetchUrl, {}, { responseType: 'arraybuffer' }) .then(function(response) { saveAs(new Blob([ response.data ], { // You need to specify the file format for the browser // to handle the download correctly. Whether this is hard-coded // or dynamically returned by your API is up to you. type: 'application/octet-stream' }), fileKey); }); } else { // Use some other method a retrieving the file, whether // that be creating an 'A' element in the DOM and triggering // the 'click' event, or using $window $window.open(fetchUrl); } }); }; 以隐藏App Bar中的阴影。

here获得解决方案: