Android Lollipop Soft Keyboard Hides User Inputs in DialogFragment - android

I am writing my first real Android application. I have an Android DialogFragment that I am displaying to allow users to add or edit details of a selected item. The DialogFragment pops up and displays fine in full screen mode. However, on the Lollipop emulator when I click on EditText widgets that are lower on the screen, the soft keyboard covers up the widget, rather than scrolling the screen up so that the user may see what they are typing. I do NOT experience this behavior in the pre-Lollipop emulator. On the KitKat emulator, the screen adjusts so that the EditText is still visible. StackOverflow will not let me post pictures yet. So, you'll have to use your imagination. :-( I have tried different ways to overcome this issue. Unfortunately, none have worked for Lollipop.
UPDATE - I have tested this on a Sony Xperia Z3 Compact running Android 5.0.2, and the DialogFragment does not scroll or adjust the screen when selecting the lower EditText widgets.
Here are the styles in use:
<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base">
<!-- Customize your theme here. -->
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:textColorPrimary">#color/colorPrimaryText</item>
<item name="android:textColorSecondary">#color/colorSecondaryText</item>
<item name="android:dialogTheme">#style/DialogTheme</item>
<item name="android:actionBarStyle">#style/AppActionBarTheme</item>
<item name="actionBarStyle">#style/AppActionBarTheme</item>"
<item name="actionBarTheme">#style/AppActionBarTheme</item>
<item name="actionBarPopupTheme">#style/AppActionBarOverflowMenuTheme</item>
<item name="windowActionModeOverlay">true</item>
</style>
<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="android:clickable">true</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowSoftInputMode">stateHidden|adjustResize</item>
<item name="windowActionModeOverlay">true</item>
</style>
As you can see in the DialogTheme, I have included the android:windowSoftInputMode attribute. I have also tried using that attribute in the AndroidManifest.xml file under the Activity that ultimately contains the DialogFragment. Here is the XML layout file for the DialogFragment:
<?xml version="1.0" encoding="utf-8"?>
<com.ahappydevelopment.android.fishtales.views.LogEditView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/dialog_margin_top"
android:background="#color/background_material_light"
android:theme="#style/DialogTheme">
<include
android:id="#+id/app_bar"
layout="#layout/app_bar_edit" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/app_bar">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<Button
android:id="#+id/btnCatchDate"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:textAllCaps="false" />
<Button
android:id="#+id/btnCatchTime"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:textAllCaps="false" />
<EditText
android:id="#+id/editLatitudeLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#id/btnCatchDate"
android:ems="10"
android:hint="#string/label_latitude"
android:inputType="numberDecimal" />
<EditText
android:id="#+id/editLongitudeLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#id/editLatitudeLabel"
android:ems="10"
android:hint="#string/label_longitude"
android:inputType="numberDecimal" />
<ImageView
android:id="#+id/imgCatchPicture"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#id/editLatitudeLabel"
android:background="#android:color/darker_gray"
android:contentDescription="#string/imgcatchpicture_contentdescription"
android:scaleType="centerInside"
android:src="#android:drawable/ic_menu_camera" />
<Spinner
android:id="#+id/spinnerLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#id/editLongitudeLabel" />
<TextView
android:id="#+id/txtFishHeader"
style="?android:attr/listSeparatorTextViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#id/spinnerLocation"
android:text="#string/section_fish" />
<Spinner
android:id="#+id/spinnerSpeciesType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#id/txtFishHeader" />
<EditText
android:id="#+id/editLengthLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#id/spinnerSpeciesType"
android:ems="5"
android:hint="#string/hint_length"
android:inputType="numberDecimal" />
<EditText
android:id="#+id/editWeightLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#id/spinnerSpeciesType"
android:ems="5"
android:hint="#string/hint_weight"
android:inputType="numberDecimal" />
<EditText
android:id="#+id/editLengthLabel2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#id/editLengthLabel"
android:ems="5"
android:hint="#string/hint_length"
android:inputType="numberDecimal" />
<EditText
android:id="#+id/editWeightLabel2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#id/editWeightLabel"
android:ems="5"
android:hint="#string/hint_weight"
android:inputType="numberDecimal" />
</RelativeLayout>
</ScrollView>
</com.ahappydevelopment.android.fishtales.views.LogEditView>
As you can see, my layout does include a ScrollView. I have even defined the android:theme="#style/DialogTheme" in the layout. I have tried setting android:fillViewport="true" on the ScrollView, as I saw in another StackOverflow posting.
On the Java side of things, I have an override for the onCreateDialog method defined as such:
#NonNull
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Dialog dialog = new Dialog(getActivity(), R.style.DialogTheme);
//set to adjust screen height automatically, when soft keyboard appears on screen
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
return dialog;
}
The Fragment that initiates the DialogFragment has a method that looks like this:
public void addLogButtonOnClickEvent() {
LogEditFragment addLog = LogEditFragment.get(0l);
if(mIsLargeLayout) {
// The device is using a large layout, so show the fragment as a dialog
addLog.show(getFragmentManager(), "AddLog");
} else {
// The device is smaller, so show the fragment fullscreen
FragmentTransaction transaction = getFragmentManager().beginTransaction();
// For a little polish, specify a transition animation
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
// To make it fullscreen, use the 'content' root view as the container
// for the fragment, which is always the root view for the activity
transaction.add(android.R.id.content, addLog).addToBackStack(null).commit();
}
}
As I said, this is working fine for the KitKat emulator. This is NOT working for the Lollipop emulator. You can see that I am trying very hard to get the DialogFragment to do adjust resize. :-) Does anyone see what I am missing or doing wrong? Also, if there is code that I have neglected to include that would help to find a solution, the please let me know, and I will post that as well. Thank you for any insight you can provide.

It took a while before I discovered this answer. I had actually refactored my DialogFragment to be an AppCompatActivity. I then began to think that perhaps the Navigation Drawer set up for Android Lollipop was perhaps to blame for the problems I was experiencing with the DialogFragment. My MainActivity layout file for API level 21 and above uses a DrawerLayout widget with a ScrimInsetsFrameLayout for the Navigation Drawer view. So, both the DrawerLayout and the ScrimInsetsFrameLayout utilize android:fitsSystemWindows="true" in their definition as part of achieving the Material Design UI specification for a Navigation Drawer. That android:fitsSystemWindows="true" in the DrawerLayout definition was interfering with the android:windowSoftInputMode="stateHidden|adjustResize" defined for the MainActivity in the AndroidManifest.xml file to cause the dialog to adjust and resize when the soft keyboard is launched. Here is the XML layout of the MainActivity:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<!-- The Main Content View -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/app_bar"
layout="#layout/app_bar_main" />
<FrameLayout
android:id="#+id/fragment_main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/app_bar" />
</RelativeLayout>
<!-- The Navigation Drawer View -->
<com.ahappydevelopment.android.fishtales.widgets.ScrimInsetsFrameLayout
android:id="#+id/scrimInsetsFrameLayout"
android:layout_width="#dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:elevation="10dp"
android:fitsSystemWindows="true"
app:insetForeground="#4000">
<FrameLayout
android:id="#+id/fragment_drawer_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</com.ahappydevelopment.android.fishtales.widgets.ScrimInsetsFrameLayout>
</android.support.v4.widget.DrawerLayout>
When telling the FragmentManager to add the DialogFragment, I was using the android.R.id.content as the view container, which is prescribed by the documentation. By experimenting with which view container to use, I was able to find one that gave the expected results. In my case, it is the DrawerLayout view defined in the MainActivity layout file.
LogEditFragment addLog = LogEditFragment.get(0l);
if(mIsLargeLayout) {
// The device is using a large layout, so show the fragment as a dialog
addLog.show(getFragmentManager(), "AddLog");
} else {
// The device is smaller, so show the fragment fullscreen
FragmentTransaction transaction = getFragmentManager().beginTransaction();
// For a little polish, specify a transition animation
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
// To make it fullscreen, use the 'drawer_layout' view
// as the container for the fragment
transaction.add(R.id.drawer_layout, addLog).addToBackStack(null).commit();
}
Once I had made these changes and refactored my LogEditFragment class to once again extend DialogFragment, both the dialog and the navigation drawer behaved as expected.

Related

Theming PreferenceFragmentCompat

I'm having some troubles setting a theme to PreferenceFragmentCompat trying to achieve this:
I have these styles set:
<style name="AppThemeBase" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:statusBarColor">#color/status_bar</item>
<item name="colorControlNormal">#color/colorPrimary</item>
<item name="preferenceTheme">#style/AppThemeBase.RecordingPreferencesTheme</item>
</style>
<style name="AppThemeBase.RecordingPreferencesTheme" parent="#style/PreferenceThemeOverlay">
<item name="android:textColorPrimary">#FD0000</item>
<item name="android:textColorSecondary">#1F6F2B</item>
</style>
With this options I can see what I want to achieve in Android Studio layout preview but when it does not have effect when I execute it
The result when I execute:
The only thing it worked so far is using <item name="android:textColor">#FD0000</item> that will change the tittle colour but I can't find a way to change the summary colour.
Another question I have is if there is a way to set the theme just for that preference fragment instead of using it in all preferences fragments. Using android:theme at the root of the fragment layout isn't working for me :(
Update:
As per #Susan question this is how I try to use android:theme at the root of the fragment layout I've created this theme based in the main one
<style name="RecordingPreferenceTheme" parent="AppThemeBase">
<item name="preferenceTheme">#style/AppThemeBase.RecordingPreferencesTheme</item>
</style>
And this is the preference layout where I have a fragment which will inflate the PreferenceFragmentCompat
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:theme="#style/RecordingPreferenceTheme">
<include
android:id="#+id/include"
layout="#layout/toolbar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<fragment
android:id="#+id/fragment_container_settings"
android:name="com.example.app.RecordSettingsFragment$RecordPreferences"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/include" />
</androidx.constraintlayout.widget.ConstraintLayout>
And at the root of the layout I'll set android:theme="#style/RecordingPreferenceTheme" but it doesn't work, just changes in the main theme set in Activity will have some effect. I've already tried customize PreferenceFragmentCompat layout with same results.
Cheers!!
See this sample project here created for your specific case the the only problem for this solution is you have to create your preference from code cant use xml file to inflate and
for those who just want the gist of this solution is that use setLayoutResource() method to set layout and use custom layout i just copied the original layout and hardcoded colors according to #Bhuntupana need
val messagesCategory = PreferenceCategory(context).apply {
layoutResource = R.layout.sample_preference
key = "messages_category"
title = getString(R.string.messages_header)
screen.addPreference(this)
}
Update
use layout tag to specify layout resource to use like this
<EditTextPreference
android:layout="#layout/sample_preference"
app:key="signature"
app:title="#string/signature_title"
app:useSimpleSummaryProvider="true" />
sample_preference.xml just copy of default layout preference_material.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:baselineAligned="false"
android:clipToPadding="false"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingRight="?android:attr/listPreferredItemPaddingRight">
<include layout="#layout/image_frame" />
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingTop="16dp"
android:paddingBottom="16dp">
<TextView
android:id="#android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceListItem"
android:textColor="#FD0000" />
<TextView
android:id="#android:id/summary"
style="#style/PreferenceSummaryTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#android:id/title"
android:layout_alignStart="#android:id/title"
android:layout_alignLeft="#android:id/title"
android:layout_gravity="start"
android:maxLines="10"
android:textAlignment="viewStart"
android:textColor="#1F6F2B" />
</RelativeLayout>
<!-- Preference should place its actual preference widget here. -->
<LinearLayout
android:id="#android:id/widget_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="end|center_vertical"
android:orientation="vertical"
android:paddingStart="16dp"
android:paddingLeft="16dp"
android:paddingEnd="0dp"
android:paddingRight="0dp" />
</LinearLayout>

DialogFragment conflict with gesture navigation

I have a Fullscreen Dialogfragment with a button in bottom-most part of the screen. In one plus 7 pro with gesture navigation enabled when we touch the lower-middle part of the "continue" button, the entire UI gets stuck other then toolbar. Navigation and everything still works.
Also when we click the button in bottom-middle part, the listener always triggers, so button click is happening, and if we minimize the app and reopen everything will start working again.
Style:-
<style name="FullScreenDialogStyle1" parent="AppTheme">
<item name="android:windowLightStatusBar">true</item>
<item name="colorPrimaryDark">#color/pure_white</item>
<item name="android:navigationBarColor">#color/veryDarkBlue
</item>
<!-- Set this to true if you want Full Screen without status bar -->
<item name="android:windowFullscreen">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
<!-- This is important! Don't forget to set window background -->
<item name="android:windowBackground">#color/transparent</item>
<!-- Additionally if you want animations when dialog opening -->
<item name="android:windowEnterAnimation">#anim/slide_up</item>
<item name="android:windowExitAnimation">#anim/slide_down</item>
</style>
Xml:-
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/pure_white"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/pure_white"
app:layout_constraintBottom_toTopOf="#id/calendar"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:navigationIcon="#drawable/ic_close_toolbar">
<mobi.hubbler.app.views.SemiBoldTextView
android:id="#+id/toolbar_title"
style="#style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="#dimen/hubbler_text_large"
android:text="#string/date_time_select" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<FrameLayout
android:id="#+id/calendar"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#id/view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/app_bar" />
<View
android:id="#+id/view"
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="#color/slot_selection_divider_bg"
app:layout_constraintBottom_toTopOf="#id/guideline6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/calendar" />
<mobi.hubbler.app.views.BoldTextView
android:id="#+id/timeSlotTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="#dimen/default_spacing_bw_views"
android:text="Time Slot"
android:textColor="#color/black"
app:layout_constraintTop_toBottomOf="#id/guideline6" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.6" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/time_list"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/timeSlotTitle"
app:layout_constraintBottom_toTopOf="#id/submitButton"
app:spanCount="3"
tools:listitem="#layout/time_select_item" />
<Button
android:id="#+id/submitButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/workflow_action_bg"
android:text="#string/continue_text"
android:textColor="#color/pure_white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
WindowInsets tell the app where the system UI appears on top of your content, along with which regions of the screen System Gestures take priority over in-app gestures. Insets are represented by the WindowInsets class and WindowInsetsCompat class in Jetpack.You can use WindowInsetsCompat to have consistent behavior across all API levels.
System insets and mandatory system insets
The following inset APIs are the most commonly used inset types:
System window insets: They tell you where the system UI is displayed over your app. We discuss how you can use system insets to move your controls away from the system bars.
System gesture insets: They return all gesture areas. Any in-app swipe controls in these regions can accidentally trigger System Gestures.
Mandatory gesture insets: They are a subset of the system gesture insets and can't be overridden. They tell you the areas of the screen where the behavior of the System Gestures will always take priority over in-app gestures.
Also, you can see this article.

How to remove space in left and right side of Action Bar when used custom layout for action bar?

I'm new to android development and I am designing an app in which I use a custom Action Bar from a layout xml file. I had done with the following code and successfully got the layout into action bar. But the problem I am getting is extra space on left and right side of the Action Bar.
I'm using the following codes.
// java code
public class SimpleQns extends AppCompatActivity{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.questions);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.actionbar_qns);
//other codes for app }
xml layout file with name actionbar_qns.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="5"
android:background="#drawable/actionbar_qns"
android:padding="0dp"
android:layout_margin="0dp">
<Button
android:id="#+id/play"
android:layout_width="50dp"
android:layout_weight="1"
android:layout_height="50dp"
android:layout_gravity="center"
android:text="P"
/>
<TextView
android:id="#+id/tv_actionbar_questions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
android:layout_gravity="center"
android:gravity="center"
android:text="Simple Questions"
android:textColor="#color/white"
android:textSize="20sp" />
<Button
android:id="#+id/stop"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="S" />
</LinearLayout>
Style.xml file
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
</resources>
How can I remove the extra space in Action Bar..?
If you want more customization on ActionBar, Use the ToolBar as an Actionbar which is more customizable than the default ActionBar.
ActionBar contains a default padding in itself. Add this line to your ActionBar xml to remove the default padding:
android:padding="0dp"

Autocompletetextview dropdown behind soft keyboard in dialog fragment

I have a dialog fragment in my app with an autocompletetextview in it, but the drop-down list instead of align with the soft keyboard's top, is placed behind, not giving access to some of the items.
Here is the layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:orientation="horizontal"
android:windowSoftInputMode="adjustPan|adjustResize">
<android.widget.AutoCompleteTextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/customDialogAtocompleteTextview"
android:layout_weight=".7"
android:layout_gravity="top" />
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".3">
<Button
android:id="#+id/customDialogBtOk"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Aceptar"/>
<Button
android:id="#+id/customDialogBtSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Buscar"/>
<Button
android:id="#+id/customDialogBtMore"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Mas"/>
</LinearLayout>
</LinearLayout>
So how can I make it to align with the keyboard?
Theory says that android:windowSoftInputMode="adjustPan|adjustResize"should do this but for some reason it doesn't, so you have to do the same programmatically:
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Aand the magic happens!!!
[update]
in my case.. cause i use bottomShetDialogFragment with autocomplete inside. drop down not show cause i not set dropdownanchor for autocomplete.
just add android:dropDownAnchor="#id/layout_above_this_autocomplete" and work perfect
ad news style in your style.xml
<style name="AppBottomSheetDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
<item name="bottomSheetStyle">#style/AppModalStyle</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowSoftInputMode">adjustResize</item>
</style>
<style name="AppModalStyle" parent="Widget.Design.BottomSheet.Modal">
<item name="behavior_peekHeight">400dp</item>
</style>
in your bottomshetdialog framgnet.
oncreate -> setStyle(DialogFragment.STYLE_NORMAL, R.style.AppBottomSheetDialogTheme)
override fun getTheme(): Int {
return R.style.AppBottomSheetDialogTheme
}

UI bug android - screen not matched on top edge

I'm working on this app and I have implemented a photo slider through ViewPager. There is an imported circle page slider indicator, a project on github. It looks like this: (Sorry for the blured text, I'm not able to share the content until release. The app will be free)
My problem is that thin blue line on the top of the screen. Blue color comes from the background and it is set in the root layout of the activity. No matter what I do to the any of the layouts (changing margins or padding to negative values) this line remains there.
So I figured that it has to do with the chosen theme for the screen. Theme is set to a custom theme which has Theme.NoTitleBar as it's parent. The code is below:
This is the style file. Taken from http://viewpagerindicator.com/ by Jake Wharton.
<style name="Theme.PageIndicatorDefaults" parent="android:Theme.NoTitleBar">
<!--<item name="vpiIconPageIndicatorStyle">#style/Widget.IconPageIndicator</item>
<item name="vpiTabPageIndicatorStyle">#style/Widget.TabPageIndicator</item>-->
<item name="vpiCirclePageIndicatorStyle">#style/Widget.CirclePageIndicator</item>
</style>
This is my activity layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/accountRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradientbg"
android:orientation="vertical"
android:gravity="bottom">
<RelativeLayout
android:id="#+id/titleBar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:visibility="visible"
>
<android.support.v4.view.ViewPager
android:id="#+id/viewPagerSlider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never"
/>
<io.colomb.android.colombio.customviews.CirclePageIndicator
android:id="#+id/slideIndicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_centerHorizontal="true"
android:layout_alignBottom="#id/viewPagerSlider"
android:layout_marginBottom="20dp"
android:paddingRight="5dp"
android:paddingLeft="5dp"
/>
</RelativeLayout>
<ImageView
android:id="#+id/ivSoftboardLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/logosoftboard"
android:layout_gravity="center_horizontal"
android:contentDescription="#string/app_name"
android:layout_marginTop="10dp"
android:visibility="gone"
android:layout_marginBottom="15dp"
/>
<LinearLayout
android:id="#+id/InputFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="0.001"
android:layout_marginTop="-15dp"
>
</LinearLayout>
Any thoughts are appreciated.
OK solved. The thing that was bothering the adapter was the line gravity="bottom"in the root element. Also the pictures needed to be cropped more

Categories

Resources