在ActionBar没有r720键盘问题解决了吗,怎么解决

在Android的原因透明状态栏隐藏键盘编辑
扫码加入我们
在Android的原因透明状态栏隐藏键盘编辑
I make an Android application, following Google's material design guidelines.
So, I've implemented the latest support libraries (my min Sdk value is 14)
Now, I face to a problem : I've made the status bar transparent, with custom ToolBar (defined in a XML file). Everything works well, except that FloatingActionButton (from ) skips XML's defined layout margin. Idem, one of my app's UI uses TextView to login the user : once focused, they're hidden by the soft keyboard.
These two problems came after replacing the main style from "AppCompat.DarkActionBar" to "AppCompat.NoActionBar" (and with item "android:windowTranslucentStatus" set to "true").
I tried to use windowSoftInputMode in my manifest with "adjustPan|adjustResize", but nothing change. Adding "ScrollView" to the layout with "EditText" inside doesn't solve my problem neither.
My english is bad, and I know that pictures are better than words, so here is what I want to do and what's happening :
(link to image)
Any ideas ? Thanks for reading !
EDIT : I solved my problem with the FloatingButton, just need to add this line to the component's XML declaration :
android:layout_alignParentBottom="true"
The only problem now is the keyboard that hides EditText.
Here is my code :
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 --&
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 --&
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 (the view with EditText's)
&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 ) --&
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 --&
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 --&
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 --&
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
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&
In my MainActivity, I have the DrawerLayout and some codelines not in relationship with the Toolbar / layout, except for :
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);
Ok, finally found a solution. Using this code in Fragment solves everything.
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
By the way, use AppCompatActivity instead of ActionBarActivity (support V7), I'm not sure it changes something, but just in case ...
(From : this answer )
日46分27秒
& 2017 内容协议先说说我的使用场景:
我写了一个activity,使用了actionbar.
在这个activity中,有fragment,默认先打开一个 homeFragment,点击某个按钮会进入 detailFragment.
当启动detailFragment 时,问题出现了:
我希望在detailFragment 打开时,actionbar出现 返回的箭头 &"&" .
于是我在onStart中写下:
public void onStart() {
super.onStart();
ActionBar actionBar = getActivity().getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setIcon(
new ColorDrawable(getResources().getColor(android.R.color.transparent))); //在这里,我把图标改成透明色了
actionbar上有了返回按钮,我希望在点击该按钮关闭 自己这个fragment
于是我监听onOptionsItemSelected事件
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
getActivity().getFragmentManager().popBackStack();
return false;
return super.onOptionsItemSelected(item);
但是,点击返回按钮后,将无法工作。你会发现&onOptionsItemSelected 不会被调用。
解决方法:在 onCreate时调用&setHasOptionsMenu(true);
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
处理homeFragment的actionbar 图标状态
由于我有了一个homeFragment,这将是我的主fragment,我希望在这个homeFragment被覆盖时,由覆盖他的fragment控制actionbar (比如变成有返回图标的样子),当覆盖他的fragment关闭,homeFragment重新出现时,还要变成原先的样子(有图标,无返回按钮)。
要达到这点,这就要获得 actionbar的图标,get 它的 Icon。
代码如下:
Drawable actionbar_lastHomeI
public void onStart() { //重新显示时,再设置会图标
super.onStart();
ActionBar actionBar = getActivity().getActionBar();
actionBar.setDisplayHomeAsUpEnabled(false);
if (actionbar_lastHomeIcon != null)
actionBar.setIcon(actionbar_lastHomeIcon);
public void onPause() {//被覆盖时,记录下 图标
super.onPause();
ImageView imageView = (ImageView) getActivity().findViewById(
android.R.id.home);
actionbar_lastHomeIcon = imageView.getDrawable();
http://stackoverflow.com/questions//actionbar-get-current-icon-findviewbyid
阅读(...) 评论()他的最新文章
他的热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)他的最新文章
他的热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)}

我要回帖

更多关于 键盘驱动有问题 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信