Android如何做向上的阴影

时间:2017-04-14 03:34:28

标签: android

Android 5.0 Material Design似乎不可能。

shadow screenshot

2 个答案:

答案 0 :(得分:0)

您可以使用“底部导航”选项卡获得此类效果。 试试这段代码希望它可以帮到你

对于底部导航选项卡,您必须将此行添加到依赖项

compile ‘com.android.support:design:25.0.0’

这是MainActivity.Java

公共类MainActivity扩展AppCompatActivity {     私人BottomBar mBottomBar;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Notice how you don't use the setContentView method here! Just
    // pass your layout to bottom bar, it will be taken care of.
    // Everything will be just like you're used to.
    mBottomBar = BottomBar.bind(this, R.layout.activity_main,
            savedInstanceState);

    mBottomBar.setItems(
            new BottomBarTab(R.drawable.ic_recents, "Recents"),
            new BottomBarTab(R.drawable.ic_favorites, "Favorites"),
            new BottomBarTab(R.drawable.ic_nearby, "Nearby"),
            new BottomBarTab(R.drawable.ic_friends, "Friends")
    );

    mBottomBar.setOnItemSelectedListener(new OnTabSelectedListener() {
        @Override
        public void onItemSelected(final int position) {
            // the user selected a new tab
        }
    });
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    mBottomBar.onSaveInstanceState(outState);
}
}

Design.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">

    <!-- Content Container -->

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:itemBackground="@color/colorPrimary"
        app:itemIconTint="@color/white"
        app:itemTextColor="@color/white"
        app:menu="@menu/bottom_navigation_main" />

</RelativeLayout>

menu.xml文件

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/action_favorites"
        android:enabled="true"
        android:icon="@drawable/ic_favorite_white_24dp"
        android:title="@string/text_favorites"
        app:showAsAction="ifRoom" />
    <item
        android:id="@+id/action_schedules"
        android:enabled="true"
        android:icon="@drawable/ic_access_time_white_24dp"
        android:title="@string/text_schedules"
        app:showAsAction="ifRoom" />
    <item
        android:id="@+id/action_music"
        android:enabled="true"
        android:icon="@drawable/ic_audiotrack_white_24dp"
        android:title="@string/text_music"
        app:showAsAction="ifRoom" />
</menu>

启用/禁用单击状态

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/white" android:state_enabled="true" />
    <item android:color="@color/colorPrimaryDark" android:state_enabled="false" />
</selector>

使用此

处理点击事件
BottomNavigationView bottomNavigationView = (BottomNavigationView)
                findViewById(R.id.bottom_navigation);

bottomNavigationView.setOnNavigationItemSelectedListener(
        new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.action_favorites:

                        break;
                    case R.id.action_schedules:

                        break;
                    case R.id.action_music:

                        break;
                }
                return false;
            }
});

答案 1 :(得分:0)

在布局中添加视图

from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor
from scrapy.http.request import Request
import scrapy

def parse_item(self, response):
    for link in response.xpath("//div[@id='siteTable']//div[@class='entry unvoted']/p[@class='title']/a/@href").extract():
        path = "https://www.reddit.com" + str(link)
        print path
        yield Request(path, callback=self.link_to_problem, errback = self.error_print)

def link_to_problem(self, response):
        print response
        print "------------------------------------------------------------------------------------------"

添加你的drawable文件夹drop_shadow.xml

<View
    android:layout_width="fill_parent"
    android:layout_height="5dip"
    android:background="@drawable/drop_shadow" >
 </View>