我的问题围绕Android Material Design中引入的浮动操作按钮.

有很多库在GitHub上提供这个组件:
但我的问题是:
是否有一个本机组件,其最后一个版本android.support.vX是为其构建的Floating action button?
组件如:
android android-support-library material-design floating-action-button android-design-library
我正在使用新的Android支持设计库.我已经在Android Developer Blogspot上关注了演示,除了我使用RecyclerView的片段而不是将它们放在同一个xml中.
这是我的activity_main.xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/drawer_layout"
>
<android.support.design.widget.CoordinatorLayout
android:layout_height="match_parent"
android:layout_width="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/toolbar"/>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
<fragment
android:id="@+id/navigation_drawer"
android:layout_marginTop="?android:attr/actionBarSize"
android:name="aungkyawpaing.yangonuniversity.Fragments.NavigationDrawerFragment"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start|left"
tools:layout="@layout/fragment_navigation_drawer"/>
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
这是toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/my_awesome_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
And this is the fragment where it has RecyclerView
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/department_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
Run Code Online (Sandbox Code Playgroud)
我在gradle中添加了最新的支持库依赖项.我看到另一个人说它不起作用,因为他在片段中使用了列表视图,但我正在使用RecyclerView.
我正在使用Android设计库TabLayout,我该如何获得当前所选项目标签位置.
ViewPager pager = (ViewPager) view.findViewById(R.id.pager);
MyPagerAdapter adapter = new MyPagerAdapter(getChildFragmentManager());
pager.setAdapter(adapter);
tabLayout.setupWithViewPager(pager);
Run Code Online (Sandbox Code Playgroud) CollapsibleToolbarLayout关于RecyclerView的行为似乎已被破坏.为...设置值时
应用:layout_scrollFlags
如果不使用"scroll | enterAlways",则Colbsible布局将永远不会展开.它总会收缩,但是当你拉下来时,它不会再展开,所以它只会被锁定在顶部.
如果您使用"scroll | enterAlways",它会按预期工作,这意味着每当您向下滚动时,它会立即将标题扩展到其完整高度.
在不知情的情况下,似乎可折叠布局无法正确确定RecyclerView何时位于列表顶部,因为这是在其他情况下何时应扩展到全高的标准.
这是我正在测试的布局.java代码并不重要,它只是使用虚拟数据和使用LinearLayoutManager填充recyclerview.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="200dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:toolbarId="@id/toolbar_id"
app:contentScrim="@color/white"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_id"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud) android android-support-library material-design android-design-library android-collapsingtoolbarlayout
错误:
07-19 16:39:56.806 29207-29207/ch.android.md E/AndroidRuntime? FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{ch.swissfm.md/ch.swissfm.md.Login}: java.lang.IllegalArgumentException: We already have an EditText, can only have one
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2200)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2262)
at android.app.ActivityThread.access$600(ActivityThread.java:148)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5145)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:802)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:569)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: We already have an EditText, can only have one
at android.support.design.widget.TextInputLayout.setEditText(TextInputLayout.java:150)
at android.support.design.widget.TextInputLayout.addView(TextInputLayout.java:139)
at ch.swissfm.md.Login.onCreate(Login.java:46)
at android.app.Activity.performCreate(Activity.java:5174)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2262)
at android.app.ActivityThread.access$600(ActivityThread.java:148) …Run Code Online (Sandbox Code Playgroud) 这篇文章说:
当你添加一个
FloatingActionButton孩子作为你的孩子,CoordinatorLayout然后将其传递CoordinatorLayout给你的Snackbar.make()电话 - 而不是显示在浮动动作按钮FloatingActionButton上的小吃店时,...当小吃店动画时自动向上移动并在小吃栏动画时返回到它的位置
我完全按照那里所描述的那样做,但FAB不会向上移动.(Snackbar可以刷掉,这意味着CoordinatorLayout知道它.)
UPD
布局:
<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/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/action_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.ActionBar"/>
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/action_toolbar"/>
</RelativeLayout>
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginTop="?attr/actionBarSize"
android:background="@color/theme_primary_darker_color"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"/>
</android.support.v4.widget.DrawerLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/toolbar_action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_navigation_white_24dp"
android:layout_margin="16dp"
android:visibility="gone"
app:borderWidth="0dp"
app:elevation="6dp"
app:layout_anchor="@id/action_toolbar"
app:layout_anchorGravity="bottom|right|end"
app:pressedTranslationZ="12dp"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
码:
mCoordinatorLayout = (CoordinatorLayout) findViewById(R.id.main_content);
...
Snackbar.make(mCoordinatorLayout, R.string.waypoint_deleted, Snackbar.LENGTH_LONG).show();
Run Code Online (Sandbox Code Playgroud) 在gradle中添加Android设计支持库后,Android工作室的构建速度非常慢
compile 'com.android.support:design:22.2.0'
但是一旦我移除上面的库就快速构建,30秒对5分钟,我正在使用库中的TabLayout和工具栏因此我需要它,不确定它是库问题还是TabLayout本身需要时间来加载,
有没有办法可以通过任何方式加快构建过程?
更新:实际原因是公司防火墙,虽然设置了代理,但是需要花费大量时间来验证每个传入的文件并导致巨大延迟,因此接受的答案应该有效以避免频繁调用
我最近使用ImageButtons,我遇到了这种新型的ImageButton'VisibilityAwareImageButton'.如果有人能告诉我这个ImageButton的用法以及它与常规的ImageButton有什么不同,那将会非常有用?提前致谢 :)
在我的应用程序中build.gradle,依赖项是:
compile 'com.android.support:support-v4:22.0.0'
compile 'com.android.support:recyclerview-v7:22.0.0'
compile 'com.android.support:cardview-v7:22.0.0'
compile 'com.android.support:support-v13:22.0.0'
compile 'com.android.support:palette-v7:22.0.0'
compile 'com.android.support:design:22.2.1'
compile 'com.android.support:percent:22.2.0'
compile 'com.google.android.gms:play-services:7.0.0'
Run Code Online (Sandbox Code Playgroud)
没有compile 'com.android.support:appcompat-v7:22.0.0',我仍然可以使用AppCompatActivity,ActionBar这是来自支持v7库.任何解释背后原因的答案将不胜感激:)
android android-appcompat android-support-library android-studio android-design-library
我正在创建一个如下工作的布局:
当我滚动时,我想在顶部工具栏和recyclerView之间隐藏工具栏.我的布局如下:
<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:fitsSystemWindows="true"
tools:context="SomeActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:layout_scrollFlags="scroll|enterAlways"/>
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="50dp"
android:minHeight="0dp"
android:id="@+id/info_bar"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
Run Code Online (Sandbox Code Playgroud)
通过这些更改,滚动时两个工具栏都会隐藏.我只需要隐藏第二个工具栏.
编辑:如果我不能让它工作,我将附加一个滚动监听器到我的recyclerView并解决这个问题.但我想知道是否有一个更清晰的滚动行为解决方案
android android-toolbar android-design-library android-coordinatorlayout