Java 有没有办法检查概览按钮?
我正在开发一个应用程序,在主屏幕上有一个左抽屉。抽屉完全适合大多数设备,但在某些设备上,无论屏幕上是否有概览按钮(手机没有物理按钮,使用屏幕按钮)或屏幕底部是否有隐藏的抽屉(大部分发生在小米身上,是的,我试过5部小米手机).这也发生在android studio的模拟器上。问题是,该应用程序是否能知道手机上是否有一个概览按钮,因此可以开发该应用程序以将布局置于其顶部(而不是覆盖)。还是有其他更简单有效的方法 以下是布局代码:Java 有没有办法检查概览按钮?,java,android,android-layout,Java,Android,Android Layout,我正在开发一个应用程序,在主屏幕上有一个左抽屉。抽屉完全适合大多数设备,但在某些设备上,无论屏幕上是否有概览按钮(手机没有物理按钮,使用屏幕按钮)或屏幕底部是否有隐藏的抽屉(大部分发生在小米身上,是的,我试过5部小米手机).这也发生在android studio的模拟器上。问题是,该应用程序是否能知道手机上是否有一个概览按钮,因此可以开发该应用程序以将布局置于其顶部(而不是覆盖)。还是有其他更简单有效的方法 以下是布局代码: <android.support.v4.widget.Drawe
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/drawer_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
<!-- *********** NAVIGATION DRAWER *********** -->
<LinearLayout
android:id="@+id/left_drawer"
android:layout_width="@dimen/drawer_width"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="@color/drawerColor"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:paddingLeft="@dimen/drawer_user_padding_left"
android:paddingBottom="@dimen/drawer_user_padding_bottom"
android:paddingTop="@dimen/drawer_user_padding_top_newest"
android:orientation="vertical" >
<TextView
android:id="@+id/referal_ID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/nav_fontsize"
android:textColor="@color/orange"
android:textStyle="bold"
android:text="\nReferal ID: " />
<TextView
android:id="@+id/profile_no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/content_fontsize"
android:textColor="@color/orange"
android:textStyle="bold"
android:text="000" />
</LinearLayout>
<LinearLayout
android:id="@+id/userdata_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/theme"
android:paddingLeft="@dimen/drawer_user_padding_left"
android:paddingTop="@dimen/drawer_separator_margin_top"
android:paddingBottom="@dimen/drawer_user_padding_bottom"
android:orientation="vertical" >
<TextView
android:id="@+id/profile_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/content_fontsize"
android:textColor="@color/white"
android:textStyle="bold"
android:text="Name" />
<TextView
android:id="@+id/profile_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/content_fontsize"
android:textColor="@color/white"
android:text="email@email.com" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/icon_point"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:adjustViewBounds="true"
android:background="@android:color/transparent"
android:src="@drawable/magno_coin"/>
<TextView
android:id="@+id/profile_credit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textSize="@dimen/content_fontsize"
android:textColor="@color/white"
android:textStyle="bold"
android:text="0"/>
</LinearLayout>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView
android:id="@+id/upper_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/drawer_upper_nav_margin"
android:isScrollContainer="false"
android:scrollbars="none" >
</ListView>
<View
android:id="@+id/upper_separator"
android:layout_width="fill_parent"
android:layout_height="@dimen/drawer_separator_height"
android:layout_marginTop="@dimen/drawer_separator_margin_top"
android:layout_marginBottom="@dimen/drawer_separator_margin_bottom"
android:background="@color/contentColor"/>
<ListView
android:id="@+id/middle_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:isScrollContainer="false"
android:scrollbars="none">
</ListView>
<View
android:id="@+id/middle_separator"
android:layout_width="fill_parent"
android:layout_height="@dimen/drawer_separator_height"
android:layout_marginTop="@dimen/drawer_separator_margin_top"
android:layout_marginBottom="@dimen/drawer_separator_margin_bottom"
android:background="@color/contentColor"/>
<ListView
android:id="@+id/lower_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:isScrollContainer="false"
android:scrollbars="none">
</ListView>
<View
android:id="@+id/lower_separator"
android:layout_width="fill_parent"
android:layout_height="@dimen/drawer_separator_height"
android:layout_marginTop="@dimen/drawer_separator_margin_top"
android:layout_marginBottom="@dimen/drawer_separator_margin_bottom"
android:background="@color/contentColor"/>
<ListView
android:id="@+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:isScrollContainer="false"
android:layout_marginBottom="@dimen/item_margin"
android:scrollbars="none">
</ListView>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="@dimen/drawer_separator_height"
android:background="@color/theme"/>
<TextView
android:id="@+id/current_version"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom|right"
android:layout_alignParentBottom="true"
android:layout_marginTop="@dimen/item_space_margin"
android:layout_marginBottom="@dimen/item_space_margin"
android:layout_marginRight="@dimen/version_margin"
android:textSize="@dimen/smaller_fontsize"
android:textColor="@color/black"
android:text="ver 1.0.0"/>
</LinearLayout>
</LinearLayout></android.support.v4.widget.DrawerLayout>
在图片上,我向下滚动直到无法再滚动为止对不起,如果我不明白你的问题
我没有在您的xmlandroid.support.design.widget.NavigationView中看到它的抽屉内容容器。您需要将implementation'com.android.support:design:27.1.1'
添加到应用程序依赖项中才能使用NavigationView
如果你想为你的抽屉做静态标题,有一个app:headerLayout=“@layout/nav_header”
属性,其中nav_header
是你的标题布局
对于其他项目,有app:menu=“@menu/drawer\u view
属性,其中drawer\u view
是您的抽屉菜单。在此菜单中,您可以根据需要放置任意数量的项目,如果需要,这些项目将可滚动。您还可以根据需要进行设计,并且在NavigationView.OnNavigationItemSelectedListener中易于处理
更多细节请参见谷歌。希望它能帮助您。这是一个常见问题。将listview(或更多)放在scrollview中是不好的。如果元素数量有限,我建议您以编程方式构建视图(使用addView)
但是,如果不想更改代码,请阅读:
基本上,在notifyDataSetChanged之后,您需要计算每个项目的listview的实际高度(getMeasuredHeight)。这将解决您的问题。要防止底部软导航栏重叠,请将其添加到values-v21目录中的styles.xml中(如果目录不存在,请创建一个,然后从value复制相同的styles.xml文件):
false
像这样-
<style name="Theme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
.....
.....
</style>
假的
.....
.....
我尝试过这个,它似乎很有效。这个在更高的API级别上也有效吗?但是,它使我定制的主题颜色不适用于更高的API级别吗?>>我没有测试过,但我认为它也应该在更高的API级别上有效。
<style name="Theme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
.....
.....
</style>