- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我按照 Google 的 Material 设计指南制作了一个 Android 应用程序。所以,我实现了最新的支持库(我的最小 Sdk 值为 14)
现在,我面临一个问题:我使用自定义工具栏(在 XML 文件中定义)使状态栏透明。一切正常,除了 FloatingActionButton(来自 https://github.com/makovkastar/FloatingActionButton)跳过 XML 定义的布局边距。 Idem,我的应用程序的一个 UI 使用 TextView 来登录用户:一旦聚焦,它们就会被软键盘隐藏。
这两个问题是在将主要样式从“AppCompat.DarkActionBar”替换为“AppCompat.NoActionBar”(并将项目“android:windowTranslucentStatus”设置为“true”)后出现的。
我尝试在我的 list 中将 windowSoftInputMode 与“adjustPan|adjustResize”一起使用,但没有任何变化。将“ScrollView”添加到内部带有“EditText”的布局也不能解决我的问题。
我的英语不好,我知道图片胜于文字,所以这是我想做的以及正在发生的事情:
(图片链接)http://i.stack.imgur.com/fIRCl.png
有什么想法吗?感谢阅读!
EDIT : I solved my problem with the FloatingButton, just need to add this line to the component's XML declaration :
android:layout_alignParentBottom="true"
现在唯一的问题是键盘隐藏了EditText。这是我的代码:
.
activity_main.xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="7dp"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- My toolbar -->
<include
android:id="@+id/tool_bar"
layout="@layout/toolbar_design">
</include>
<!-- Fragment's place -->
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true">
</FrameLayout> <!-- Open drawer bug fix -->
</LinearLayout>
<!-- Sliding Drawer -->
<ListView
android:id="@+id/list_slidermenu"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@null"
android:clipToPadding="false"
android:overScrollFooter="@android:color/transparent"
android:dividerHeight="0dp"
android:background="@color/drawer_background"/>
</android.support.v4.widget.DrawerLayout>
toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/md_blue_800"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
android:elevation="4dp" >
</android.support.v7.widget.Toolbar>
fragment_profile.xml(带有 EditText 的 View )
<LinearLayout 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="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/container_dropshadow">
<!-- Top fragment's Image -->
<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:scaleType="centerCrop"
android:src="@drawable/top_image"/>
</LinearLayout>
<!-- Scrollview in case of screen's height is too small -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:id="@+id/rlFillProfile">
<!-- long long text ( 9 lines ) -->
<TextView
android:text="@string/text_edit_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:id="@+id/tvEditProfile" />
<!-- User ID EditText -->
<com.rengwuxian.materialedittext.MaterialEditText
android:layout_below="@id/tvEditProfile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:maxLines="1"
android:singleLine="true"
android:maxEms="10"
android:hint="Your user ID"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:id="@+id/etUserID"
android:layout_alignLeft="@+id/etUserPassword"
android:layout_alignStart="@+id/etUserPassword" />
<!-- User ID TextView -->
<TextView
android:id="@+id/tvUserID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Identifiant :"
android:textSize="18dp"
android:layout_marginBottom="16dp"
android:layout_alignBottom="@id/etUserID"
android:layout_alignRight="@+id/tvUserPassword"
android:layout_alignEnd="@+id/tvUserPassword" />
<!-- User password TextView -->
<com.rengwuxian.materialedittext.MaterialEditText
android:layout_below="@id/etUserID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:maxLines="1"
android:singleLine="true"
android:maxEms="10"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:inputType="textPassword"
android:id="@+id/etUserPassword"
android:hint="******"
android:layout_toRightOf="@+id/tvUserPassword"
android:layout_toEndOf="@+id/tvUserPassword" />
<!-- User password TextView -->
<TextView
android:id="@+id/tvUserPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mot de passe :"
android:textSize="18dp"
android:layout_alignBottom="@+id/etUserPassword"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<!-- Button to get user's touch event -->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Continuer"
android:id="@+id/button_disconnect"
android:layout_below="@id/etUserPassword"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</ScrollView>
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" ... >
<!-- Permissions -->
...
<application
... >
<activity
android:name="..."
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden"
android:windowSoftInputMode="adjustResize|stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
在我的 MainActivity 中,我有 DrawerLayout 和一些与工具栏/布局无关的代码行,除了:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
toolbar = (Toolbar) findViewById(R.id.tool_bar);
toolbar.setPadding(0, getStatusBarHeight(), 0, 0);
setSupportActionBar(toolbar);
// enabling action bar app icon and behaving it as toggle button
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
...
}
// A method to find height of the status bar
// Source : an Stackoverflow's answer
public int getStatusBarHeight() {
int result = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = getResources().getDimensionPixelSize(resourceId);
}
return result;
}
最佳答案
好的,终于找到解决办法了。在 Fragment 中使用此代码可以解决所有问题。
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
顺便说一下,使用 AppCompatActivity 而不是 ActionBarActivity(支持 V7),我不确定它会改变什么,但以防万一......
关于android - Android中的透明状态栏导致EditText被键盘隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31867595/
/** Called when the user clicks the Send button */ public void sendMessage(View view) { Intent i
我已经编写了 EditText 的子类。这是那个子类: package com.package.foo; import android.content.Context; import android.
我有一个用户名和密码 XML 段 我希望当用户名字段到达第9个字符时光标焦点自动跳转到密码字段 我在看 Focus next textview automatically并且正在尝试: fin
我知道这类问题被问过很多次。但仍然没有人给出完美的答案。 我有问题: 我想从 EditText1 ** 移动到另一个 **EditText2 。我已经检测到editText1,但如何将光标移动到edi
我有 2 个 EditText(myEditText1 和 myEditText2) 我需要触摸 myEditText1 1.做一些生意[这里没有问题,需要申请的业务] 2. 然后请求焦点到 myEd
我想在用户输入 EditText 时将文本放入我的应用程序中的某个字符串中,并使用它在 Activity 中生动地显示它(在不同的 View 中......) - 就像谷歌的实时/即时搜索一样...
当我将文本插入到我的 EditText 字段时,文本本身与 EditText 的行之间存在异常间隙。这是我终端的打印屏幕,您可以在其中看到我正在谈论的这个差距,它被标记为红色。 我试过文本对齐和引力但
我的应用程序需要帮助。这是我的相对布局的 xml 文件,我需要在按下 Enter 键后跳转到下一个编辑文本。但是有一个问题,如果我正在写入 editTextKm 并按 Enter 键,它会跳转到 ed
Hello All 我已经将 onLongClickListener() 用于我的 EditText View ,但是每当我长时间单击 View 时,就会出现一个弹出窗口,不允许我执行我的操作onLo
EditText 快把我们逼疯了!真的! 我们的应用程序登录屏幕出现问题。它包含两个 EditText,但只有第一个(用户名)获得焦点,通过 SoftKeyboard 仅在触摸/单击用户名 EditT
如何在kotlin中获取editText并用toast显示。 var editTextHello = findViewById(R.id.editTextHello) 我试过了,但显示对象 Toast
我一直在浏览各种线索来解决这个问题,但我仍然感到困惑。当我将“adjustPan”应用于底部具有 EditText 的 Activity 时,UI 会正确向上推,但编辑文本会被底部的键盘稍微遮挡。经过
我有两个类:a 和 b。在类 a 中,我有一个线程,当变量 x 的值小于 1000 时,它会将变量 x 加一。在类 b(Activity 类)中,我有一个名为 ed 的 EditText。每当a类中x
今天我遇到了一个非常有趣的情况。 假设: EditText 从 XML 实例化。 EditText editText; editText = findViewByID(R.id.editT
有谁知道我的代码出了什么问题,我正在尝试比较编辑文本字段中的输入,以确保它们在创建帐户之前具有相同的值。 //compare the fields contents if(editT
制作一个简单的卡路里转换器。 这是图片中的问题。 我使用的是 Genymotion 模拟器。 这是我遇到问题的屏幕部分: 当我单击 EditText 数字字段时,数字键盘会出现 但是我必须单击下一个箭
全部 - 我试图隐藏 EditText B、C,直到 EditText A 中至少有一个字符。我尝试过使用文本观察器... EditText editText = (EditText) findVie
我正在努力完成 “Sam 的 24 小时 Android 应用程序开发技术”,但在某些时候我的昵称和电子邮件设置停止正确保存。它现在根本不保存昵称并将电子邮件保存到两者。我做了什么导致这个,我该如何解
我有一个 SharedPreferences,它保存来自一个 Activity 的 EditText 输入并在另一个 Activity 中显示字符串值。 当我在 EditText 字段中输入内容并按下
这一定是一个我可能会再次忽略的简单问题。这是我的问题我的 string.xml 上有一个字符串数组 Alabama Florida Los Angeles Virgi
我是一名优秀的程序员,十分优秀!