我想开发一个即使使用 dpad 也能 100% 运行的应用程序,但不适用于电视设备,所以我不想依赖 Leanback 库。我已经遵循了这里的指南,以便集中我的 UI 的正确元素。
\n\n我正在使用支持设计库,但我的设计遇到了一些问题NavigationView:
这就是我正在做的处理焦点的事情:
\n\nprivate void initDrawer(){\n drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);\n navigationView = (NavigationView)findViewById(R.id.navigation_view);\n navigationView.setNavigationItemSelectedListener(this);\n drawerToggle = new ActionBarDrawerToggle(MainActivity.this, drawerLayout, R.string.app_name, R.string.app_name){\n @Override\n public void onDrawerOpened(View drawerView) {\n super.onDrawerOpened(drawerView);\n //This is not working properly\n navigationView.requestFocus();\n }\n\n @Override\n public void onDrawerClosed(View drawerView) {\n super.onDrawerClosed(drawerView);\n //This seems to work\n mContentLayout.requestFocus();\n }\n };\n drawerLayout.setDrawerListener(drawerToggle);\n}\nRun Code Online (Sandbox Code Playgroud)\n\n这就是我正在做的使用硬件按钮切换抽屉打开/关闭的操作:
\n\n@Override\npublic boolean onKeyUp(int keyCode, KeyEvent event){\n if(keyCode==KeyEvent.KEYCODE_BUTTON_Y){\n …Run Code Online (Sandbox Code Playgroud) android android-support-library androiddesignsupport android-navigationview
我想在我的应用程序中使用新的设计支持库,从API 21开始.我想使用Theme.Material样式,但它仅适用于Theme.AppCompat样式.当我使用Theme.Material时,android会返回此错误:
错误膨胀类android.support.design.widget.textinputlayout"
我该如何解决?
先感谢您
Ps:抱歉我的英语不好,我是法国人.
更新: 这是我的代码
styles.xml
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
<item name="android:colorPrimary">@color/primary</item>
<item name="android:colorPrimaryDark">@color/primary_dark</item>
<item name="android:colorAccent">@color/accent</item>
<item name="android:colorControlNormal">@color/control_normal</item>
<item name="android:textColorHint">@color/silver</item>
</style>
Run Code Online (Sandbox Code Playgroud)
activity.xml
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="username"
android:id="@+id/editText1" />
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
的build.gradle
dependencies {
//compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':facebook')
compile('com.twitter.sdk.android:twitter:1.1.0@aar') {
transitive = true;
exclude module: 'gson'
}
compile 'com.google.android.gms:play-services-plus:7.5.0'
compile 'com.google.android.gms:play-services-identity:7.5.0'
compile 'com.android.support:design:22.2.0'
compile 'com.android.support:support-v13:22.0.0'
compile 'com.android.support:cardview-v7:22.0.0'
compile 'com.soundcloud.android:android-crop:0.9.10@aar'
compile files('libs/volley.jar')
compile files('libs/gson-2.3.1.jar')
compile files('libs/httpclient-4.3.3.jar')
compile files('libs/httpclient-cache-4.3.3.jar')
compile files('libs/httpcore-4.3.2.jar')
compile files('libs/httpmime-4.3.3.jar')
compile files('libs/commons-lang3-3.3.2.jar')
compile …Run Code Online (Sandbox Code Playgroud) android android-5.0-lollipop material-theme android-design-library androiddesignsupport
使用具有以下视图层次结构的设计支持库22.2.1:
<DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" />
<TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
app:tabGravity="fill"
app:tabMode="scrollable" />
</AppBarLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior">
<!-- Fragments replaced here -->
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<CustomDashboardView
android:layout_width="match_parent"
android:layout_height="120dp" />
<ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Tab Fragments go here -->
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<CustomEmptyErrorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</ViewPager>
</LinearLayout>
</FrameLayout>
</CoordinatorLayout>
<NavigationView
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:fitsSystemWindows="true" />
</DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
我遇到了一个问题,其中RecyclerView的高度大于应包含该可见区域的可见区域,因此RecyclerView看起来像在屏幕外绘制,并且不可能将RecyclerView中的最后一项滚动到完整视图。关于工具栏和TabLayout也没有任何变化(尽管layout_behaviour应用于FrameLayout)。
我曾将其报告为错误,但是ol'Banesy表示这已按预期进行。如果是这种情况,我如何避免这种预期的行为,而使用RecyclerView,它尊重layout_height =“ match_parent”并在可见屏幕内绘制其项目?https://code.google.com/p/android/issues/detail?id=182391
更新:现在有了Design Support …
android android-recyclerview androiddesignsupport android-coordinatorlayout
我有一个相当复杂的自定义工具栏 (android.support.v7.widget.Toolbar),它是通过 xml 创建的:
(例如简化的例子)
<android.support.v7.widget.Toolbar>
<ImageView/>
<TextView/>
</android.support.v7.widget.Toolbar>
Run Code Online (Sandbox Code Playgroud)
这很好用,除非我最终在我的 ImageView 的左边有边距/填充。toolbar.setNavigationIcon(null)不会改变任何东西。更改填充和边距似乎没有任何作用。我不确定这是从哪里来的。
我该如何摆脱这个?
我试图使用ScrollView使用CollapsingToolbarLayout,但我没有让它工作.我试试这个:
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_below="@+id/toolbar"
android:scrollbars="none"
android:overScrollMode="never"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:behavior_overlapTop="192dp"
android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent"
android:orientation="vertical"
android:padding="@dimen/medium_padding"
android:layout_height="match_parent">
<!-- my content -->
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"></android.support.v7.widget.Toolbar>
<ImageView
android:src="@drawable/fondo_drawer"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
app:layout_collapseMode="parallax"
android:minHeight="100dp"/>
</android.support.design.widget.CollapsingToolbarLayout>
Run Code Online (Sandbox Code Playgroud)
我用ScrollView和NestedScrollView测试失败了.
有任何想法吗?提前致谢!
我想滚动用户说明,但layout_scrollFlags ="滚动"不适用于RelativeLayout.ViewPager有2个片段,里面有SwipeRefreshLayout和RecyclerView.如何在CollapsingToolbar exitUntilCollapsed时滚出描述?
<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/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/user_background"
android:layout_width="match_parent"
android:layout_height="192dp"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="@dimen/keyline_1">
<ImageView
android:id="@+id/avatar"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="@dimen/keyline_1"
android:layout_marginStart="@dimen/keyline_1" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/keyline_1"
android:layout_marginStart="@dimen/keyline_1"
android:layout_toEndOf="@id/avatar"
android:layout_toRightOf="@id/avatar"
android:orientation="vertical">
<TextView
android:id="@+id/full_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Body2" />
<TextView
android:id="@+id/screen_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
</LinearLayout>
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
<RelativeLayout
android:id="@+id/information"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll">
<TextView
android:id="@+id/bio"
android:layout_width="wrap_content" …Run Code Online (Sandbox Code Playgroud) android-design-library androiddesignsupport android-collapsingtoolbarlayout android-appbarlayout android-tablayout
我在这里读了android-developers的新博文.
TextInputLayout 扩展了浮动提示文本和错误指示符的现有功能,并增加了对字符计数的支持.
但我找不到任何编程方式的字符计数代码支持.我想一些代码来实现的字符计数使用TextInputLayout
我已经根据支持更新 23.2成功实现了底片,但是当底片展开时,我没有获得稀松布颜色(窗口变暗)效果。我看到coordinatorlayout包含一个getscrimcolor方法但没有设置。
android android-layout android-studio androiddesignsupport android-coordinatorlayout
我想在我的Navigation Drawer. 此图显示了最初进行的选择(默认情况下不是用户)。
我已经通过以下代码实现了这一点
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="Category">
<menu>
<group android:checkableBehavior="single">
<item
android:id="@+id/coaching"
android:icon="@drawable/coaching"
android:title="Coaching"
android:checked="true"/>
<item
android:id="@+id/training"
android:icon="@drawable/training"
android:title="Training"/>
</group>
</menu>
</item>
<group android:checkableBehavior="single">
<item
android:id="@+id/new_registrations"
android:icon="@drawable/new_registrations"
android:title="New Registrations"
android:checked="true"/>
<item
android:id="@+id/ready_certificates"
android:icon="@drawable/ready_certificates"
android:title="Certificates Ready To Collect"/>
<item
android:id="@+id/allotted_certificates"
android:icon="@drawable/allotted_certificates"
android:title="Certificates Allotted So Far"/>
</group>
Run Code Online (Sandbox Code Playgroud)
但问题是当我手动选择任何项目时,所有先前从两个组中选择的项目都会被取消选择。所以我想验证第一组中的一项选择和第二组中的一项选择。寻找缺失的属性。
我想在BottomNavigationView的菜单项中设置特定的图像,因为当我使用drawable设置图像时,它无法正常工作。
您还可以指导我如何显示活动的臀部...吗?
这是我的代码。
selectedActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".selectedJokesActivity">
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="454dp">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
selectedActivity.xml
我的活动的屏幕截图:-
menu / navigation.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/navigation_home"
android:icon="@drawable/digital"
android:title="@string/title_home" />
<item
android:id="@+id/navigation_dashboard"
android:icon="@drawable/ic_dashboard_black_24dp"
android:title="@string/title_dashboard" />
<item
android:id="@+id/navigation_notifications"
android:icon="@drawable/ic_notifications_black_24dp"
android:title="@string/title_notifications" />
</menu>
Run Code Online (Sandbox Code Playgroud)
请帮忙....
java android android-menu androiddesignsupport android-bottomnav