标签: androiddesignsupport

动态更改导航视图项目颜色Android

我想建立一个导航抽屉,其中每个项目都有不同的选择颜色(图标色调和文本颜色),因为谷歌游戏商店有:

在此输入图像描述

我不确定他们是如何解决的,我认为他们使用不同的抽屉活动.我想使用片段,我想更改图标色调和文本颜色.我有什么想法可以做到这一点?我正在使用谷歌的设计支持库和带有导航视图的抽屉布局.

android drawerlayout navigationview androiddesignsupport

15
推荐指数
2
解决办法
1万
查看次数

从支持设计库使用新的TextInputLayout时出现RuntimeException

我有一个非常简单的布局,我使用Design Support Library中的android.support.design.widget.TextInputLayout视图

<android.support.design.widget.TextInputLayout
    android:id="@+id/til"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <EditText
        android:id="@+id/textDialog"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="First Name"/>
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)

在膨胀时,我得到例外:

Caused by: java.lang.RuntimeException: Failed to resolve attribute at index 18
            at android.content.res.TypedArray.getColor(TypedArray.java:401)
            at android.support.design.widget.CollapsingTextHelper.setCollapsedTextAppearance(CollapsingTextHelper.java:166)
            at android.support.design.widget.TextInputLayout.<init>(TextInputLayout.java:106)
            at java.lang.reflect.Constructor.newInstance(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
            at android.view.LayoutInflater.createView(LayoutInflater.java:607)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:381)
            at android.app.Activity.setContentView(Activity.java:2144)
            at com.example.trybindinglib.MainActivity.onCreate(MainActivity.java:24)
            at android.app.Activity.performCreate(Activity.java:5933)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2407)
            at android.app.ActivityThread.access$800(ActivityThread.java:149)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:211)
            at android.app.ActivityThread.main(ActivityThread.java:5321)
            at java.lang.reflect.Method.invoke(Native Method)
            at …
Run Code Online (Sandbox Code Playgroud)

layout android android-design-library androiddesignsupport

14
推荐指数
3
解决办法
1万
查看次数

自定义主题干扰快餐栏背景颜色

试用新的设计支持库,我添加了一个小吃吧; 但与其主背景不同,文本区域未使用默认值着色#323232.相反,它看起来像这样.它似乎从android:background我自定义主题中定义的值中获取颜色styles.xml,如下所示:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    ...
    <item name="android:background">#4f4f5e</item>
    ...
</style>
Run Code Online (Sandbox Code Playgroud)

如果我试着用它强行着色

View snackbarView = snackbar.getView(); 
snackbarView.setBackgroundColor(Color.YELLOW);
Run Code Online (Sandbox Code Playgroud)

它只影响主背景,像这样,文本背景仍然被自定义主题着色.有没有办法保持我的自定义主题,并有一个标准的小吃吧?谢谢!

android material-design android-design-library android-snackbar androiddesignsupport

14
推荐指数
3
解决办法
1万
查看次数

CollapsingToolbarLayout crash on 4.4 devices (java.lang.IllegalArgumentException: radius must be > 0)

I have implemented the new style Collapsible Toolbar. I am using the same code as the example (Cheesesquare) demo app - which of course works fine on all devices. I need help figuring out what I am doing different then the sample (so my app won't crash).

My app runs great on 5.0+ devices, but crashes on older devices (OS 4.4.4) with an error that I can't isolate to my code (no references to my project's classes in the stack). …

android android-toolbar androiddesignsupport

14
推荐指数
2
解决办法
4142
查看次数

禁用工具栏滚动

我有当前的设置:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordiator_layout_in_main"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.AppBarLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <android.support.design.widget.NavigationView
        android:layout_width="170dp"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"/>

    <FrameLayout
        // I place a fragment containing a viewpager containing    fragments that contain a recyclerview.... 
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_toRightOf="@+id/nav_view">

    </FrameLayout>
</RelativeLayout>

<FrameLayout
    android:id="@+id/settings_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="invisible">
</FrameLayout>

<android.support.design.widget.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_refresh"
    app:layout_anchor="@id/coordiator_layout_in_main"
    app:layout_anchorGravity="bottom|right|end"   
   app:layout_behavior="com.material.widget.MyFloatingActionButtonBehavior" />

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

现在一切都按预期工作,如果我在包含片段的framelayout内滚动,工具栏可以根据需要滑入和滑出

现在重点是,如果我滚动位于framelayout侧面的NavView(以及relativelayout内部),我想禁用工具栏滑入和滑出

但无论我是否删除所有滚动行为,工具栏都会继续滑入和滑出(只有禁用它的方法是从appbarlayout中移除滚动标记,但禁止所有滑入和滑出tolbar)

请问我在这里错过了什么?是不是应该将滚动事件传递给CoordinatorLayout的scolling行为?

android android-design-library androiddesignsupport android-coordinatorlayout android-appbarlayout

14
推荐指数
3
解决办法
1957
查看次数

TabLayout选择了标签重力

TabLayout设置有ViewPager,有很多标签MODE_SCROLLABLE和keyline app:tabContentStart="72dp".

当用户选择选项卡时,TabLayout尝试将所选选项卡滚动到中心.我希望选中的选项卡与keyline保持对齐,而不是居中.可能吗?

Android设计支持库v22.2.0.

android android-design-library androiddesignsupport android-tablayout

13
推荐指数
2
解决办法
2564
查看次数

CollapsingToolbarLayout中的工具栏,工具栏标题未显示

我用它CollapsingToolbarLayout作为父母Toolbar,在它下面布局

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/test_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:minHeight="?attr/actionBarSize"
            app:navigationIcon="@drawable/abc_ic_ab_back_mtrl_am_alpha"
            app:theme="@style/ThemeOverlay.AppCompat.Light" />

    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)

然后我想Toolbar用以下代码设置标题,但它不起作用.标题只是没有显示.

    Toolbar toolbar = (Toolbar) findViewById(R.id.test_toolbar);
    setSupportActionBar(toolbar);

    getSupportActionBar().setDisplayShowTitleEnabled(true);
    getSupportActionBar().setTitle("ABC");
Run Code Online (Sandbox Code Playgroud)

我也尝试CollapsingToolbarLayout使用以下代码设置标题,它也不起作用.

    CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar_layout);
    collapsingToolbarLayout.setTitleEnabled(true);
    collapsingToolbarLayout.setTitle("ABC");
Run Code Online (Sandbox Code Playgroud)

但是,如果我CollapsingToolbarLayout从我的布局中删除并AppBarLayout作为直接父代Toolbar,上面的代码设置工作的标题Toolbar.

我错过了什么吗?这个问题太奇怪了.这是设计支持库中的错误吗?如何在不改变布局的情况下解决问题?

android android-toolbar androiddesignsupport android-collapsingtoolbarlayout

13
推荐指数
1
解决办法
4556
查看次数

在CoordinatorLayout中平移谷歌地图会导致recyclerview在android设计支持库23.0.1中滚动

该地图位于collapsingToolbarLayout中,该套接字嵌套在appBarLayout中.在android设计支持库的22.2.0和22.2.1版本中,我可以独立于coordinatorLayout平移地图,但在23.0.1中,如果我尝试在北/南轴上平移地图,则会导致recyclelerview向上/向下滚动.这是一个错误还是有办法将触摸事件从appBarLayout传递到mapFragment?

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways">

        <fragment
            android:id="@+id/mapFragment"
            android:name="com.google.android.gms.maps.MapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_collapseMode="parallax" />


    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#44CCFF"
    app:behavior_overlapTop="184dp"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|right"
    android:layout_margin="16dp"
    android:src="@drawable/ic_list_white_24dp"
    app:backgroundTint="#3366FF"
    app:fabSize="normal" />
Run Code Online (Sandbox Code Playgroud)

android google-maps androiddesignsupport android-coordinatorlayout

13
推荐指数
2
解决办法
5025
查看次数

在Android中将状态栏填充设置为NavigationView

我有一个活动,它从支持库托管DrawerLayout和NavigationView.我正在为导航视图设置标题布局,我希望导航标题高度为"wrap_content".因此,当我将高度设置为"wrap_content"时,标题布局会位于状态栏后面.

我想要的结果是导航抽屉应该在状态栏后面绘制,但导航标题应该按状态栏高度向下推.

下面是我得到的截图.请注意状态栏后面的"SIGN IN"按钮.

截图

活动布局

<android.support.v4.widget.DrawerLayout
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:id="@+id/nav_drawer"
android:fitsSystemWindows="true">

<android.support.design.widget.CoordinatorLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"></android.support.v4.view.ViewPager>
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    <include layout="@layout/include_toolbar"/>

        <android.support.design.widget.TabLayout
            app:theme="@style/ThemeOverlay.AppCompat.Dark"
            style="@style/MyCustomTabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/tabs"
            />

    </android.support.design.widget.AppBarLayout>

</android.support.design.widget.CoordinatorLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    app:headerLayout="@layout/nav_header"
    app:menu="@menu/menu_navigation"
    android:fitsSystemWindows="true"
    android:layout_gravity="start"/>

</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)

导航视图标题布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="?attr/colorPrimaryDark"
          android:padding="16dp"
          android:theme="@style/ThemeOverlay.AppCompat.Dark"
          android:orientation="vertical"
          android:fitsSystemWindows="true"
          android:gravity="bottom">

<TextView
    android:visibility="gone"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/text_user_name"
    android:textAppearance="@style/TextAppearance.AppCompat.Body1"/>

<TextView
    android:visibility="gone"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/text_email"
    android:textAppearance="@style/TextAppearance.AppCompat.Body2"/>

<Button
    android:id="@+id/button_sign_in"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Sign In"/>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我通过StackOverflow搜索了一个解决方案,但找不到它.所以有人请说清楚.提前致谢.

android navigation-drawer material-design navigationview androiddesignsupport

13
推荐指数
2
解决办法
7505
查看次数

支持库24.2.1中锚定FloatingActionButton的错误

我从24.2.0开始就遇到过这个问题,但现在我正在使用24.2.1并且bug仍在这里,它只能很好地运行<= 24.1.1.

我有一个像这样的锚定FloatingActionButton:

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/contact_coordinator_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:context="es.cocode.baseapp.contact.ContactFragment">

        <FrameLayout
            android:id="@+id/map_fragment_container"
            android:layout_width="match_parent"
            android:layout_height="198dp"
            android:layout_marginBottom="210dp">

            <fragment
                android:id="@+id/map_fragment"
                android:name="com.google.android.gms.maps.SupportMapFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

        </FrameLayout>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab_fullscreen_map"
            android:src="@drawable/ic_fullscreen_white_48dp"
            android:layout_width="56dp"
            android:layout_height="56dp"
            android:layout_margin="@dimen/fab_margin"
            app:layout_anchor="@id/map_fragment_container"
            app:layout_anchorGravity="bottom|end" />

    </android.support.design.widget.CoordinatorLayout>

</ScrollView>
Run Code Online (Sandbox Code Playgroud)

它通常像这样工作:

FAB运作良好

但有时会出现错误,锚点不起作用:

FAB无法正常工作

有没有办法解决这个问题,还是应该等到这个bug得到修复并使用24.1.1代替?

android android-support-library floating-action-button android-design-library androiddesignsupport

13
推荐指数
1
解决办法
1357
查看次数