I am having an issue with the keyboard. When it disappears, the space it occupied remains blank and the rest of the layout does not adjust
normal screen:
with keyboard:
keyboard dismissed:
I have never seen this before, so I am not even sure where to start looking. This happens on 4.2.2 as well as 5.1
The other piece of important information is that this is a custom LinearLayout that holds all of the content. Maybe it has something to do with that. I can upload any code if necessary.
This is the main layout file shell.
<com.edgetechlabs.app_v2.MasterLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Menu (Drawer)-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:visibility="visible"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/activity_main_menu_listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/drawer_background"
android:cacheColorHint="#00000000" >
</ScrollView>
</LinearLayout>
<!-- Fragment Holder -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- This is where fragment will show up -->
<FrameLayout
android:id="#+id/fragment_master"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</LinearLayout>
This is my manifest file
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MasterActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
I added
android:windowSoftInputMode="adjustPan"
to my manifest within the activity tag, and now it works. I have never had to do that before, I guess my custom layout was messing with the keyboard somehow.
Thanks to #eee comment which pointed me in the right direction
try to change ScrollView to androidx.core.widget.NestedScrollView
this helped me to fix the problem
if you dont have set adjustPan set in your activity in AndroidManifest.xml f.e you need adjustResize then this was the only solution which helped me with that white blank space
EditText.setOnFocusChangeListener { v, hasFocus ->
if (hasFocus) {
// something if needed
} else {
Utils.hideKeyboardToAdjustPan(activity)
}
}
fun hideKeyboardToAdjustPan(activity: Activity?) {
activity?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
hideKeyboard(activity)
}
fun hideKeyboard(activity: Activity?) {
if (activity != null) {
hideKeyboard(activity.currentFocus)
}
}
fun hideKeyboard(view: View?) {
if (view != null) {
val inputManager = view.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputManager.hideSoftInputFromWindow(
view.windowToken,
WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED
)
}
}
Related
We have an app that display content edge-to-edge and for some core functionalities uses webview.
We have noticed that when the keyboard is open on webview the scroll stop working properly. It is impossible scroll and see the bottom of page without close the keyboard.
We create a simpler demo app (code bellow) with the same configuration and with the same issue. Considering the requirements demand content to be presented edge-to-edge is there a way to fix the webview scroll?
Activity:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//the webview scrool do not work properly with this lines
WindowCompat.setDecorFitsSystemWindows(window, false)
window.setStatusBarColor(Color.TRANSPARENT);
window.setNavigationBarColor(Color.TRANSPARENT);
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
ViewCompat.setOnApplyWindowInsetsListener(binding.toolbar) { view, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
// Apply the necessary top margin
val mlpHeader = view.getLayoutParams()
if (mlpHeader is ViewGroup.MarginLayoutParams){
mlpHeader.topMargin = insets.top;
}
// Return CONSUMED if you don't want want the window insets to keep being
// passed down to descendant views.
WindowInsetsCompat.CONSUMED
}
setSupportActionBar(binding.toolbar)
binding.webview.loadUrl("https://www.google.com")
}
Layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/Theme.MyApplication.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/Theme.MyApplication.PopupOverlay" />
</com.google.android.material.appbar.AppBarLayout>
<WebView
android:id="#+id/webview"
android:layout_marginTop="?attr/actionBarSize"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
enter code here
manifest
<activity
android:name=".MainActivity"
android:exported="true"
android:label="#string/app_name"
android:theme="#style/Theme.MyApplication.NoActionBar"
android:windowSoftInputMode="adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
On the first image demo app is displaying contente edge-to-edge: scroll is not working properly.
On the second imagem app is not displaying contente edge-to-edge: scroll is working properly
I want to have a (semi-)transparent view on top of another view (a map) where I can place various elements as an overlay. With my current setup I have two problems, as shown in the image below:
a. the test rectangle appears always at the bottom (as a test I want it 40dp from the top)
b. the view is not entirely transparent, there is a greyish area above my test-rectangle
my layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/landmark"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="40dp">
<ImageView
android:id="#+id/box"
android:src = "#drawable/rectangle"
android:layout_alignParentBottom = "true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
activity class:
class LandmarkActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_landmark)
}
}
manifest:
<activity android:name=".LandmarkActivity"
android:launchMode="singleTask"
android:theme="#style/Theme.AppCompat.Dialog"
android:windowSoftInputMode="adjustResize|stateHidden"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
try with this, without layout_alignParentBottom and with proper top margin set
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/landmark"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="#+id/box"
android:src = "#drawable/rectangle"
android:layout_marginTop="40dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
ImageView have android:src = "#drawable/rectangle" with sizes set as wrap_content so size of this View depends on your drawable. you may consider adding adjustViewBounds and scaleType xml attrs to ImageView, but without actual real rectangle drawable its hard to guess is this will help
This is for a school project, but i didn't understand many parts of this.
I am leaving the handling of the rotation to the system, but after describing 2 layouts (standart and landscape mode)
But the landscape mode layout won't be taken into account when I rotate the screen.
(source: hostingpics.net)
(I have pressed the 4th button, in case it is the issue ...)
The mainactivity extends AppCompatActivity, (Because our teacher told us to), and all I do (for now) in the MainActivity is
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(TAG,"Test");
}
then I described 2 LinearLayouts, one in layout/activity_main.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:orientation="vertical"
android:baselineAligned="false"
android:divider="#drawable/empty_divider_tall"
android:showDividers="middle"
android:background="#color/fl_concrete"
>
<fragment
class="com.example.g20901528.androidproject.fragment.TopFragment"
android:id="#+id/fragment_top"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_width="match_parent"
/>
<fragment
class="com.example.g20901528.androidproject.fragment.BottomFragment"
android:id="#+id/fragment_bottom"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
and another in layout-land/activity-main.xml which is almost the same :
edit : layout-land/activity_main.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:orientation="horizontal"
android:baselineAligned="false"
android:divider="#drawable/empty_divider_wide"
android:showDividers="middle"
android:background="#color/fl_concrete"
>
<fragment
class="com.example.g20901528.androidproject.fragment.TopFragment"
android:id="#+id/fragment_top"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_width="match_parent"
/>
<fragment
class="com.example.g20901528.androidproject.fragment.BottomFragment"
android:id="#+id/fragment_bottom"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
I did not change my manifest aside describing the MainActivity :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.g20901528.androidproject">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
My question is : how to make it so the two fragments rotate when i rotate the phone ?
I'm ready to provide any information.
Github Link of the project, if you really need it.
dude your layout xml name is different please change that
layout/activity_main.xml
layout-land/activity-main.xml make it -->
layout-land/activity_main.xml
and run
I want to create an android application which has 3 sliding tab panel and each of them will 5 button (save,new,delete,exit..).
What I want is exactly as follow:
I created sliding tab panel.And for 5 button, I added split action bar.But It works as normal split action bar.My AndroidManifest.xml is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.belsoft.myapplication">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:uiOptions="splitActionBarWhenNarrow"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Where is my wrong?
To implement splitActionBar:
Just add android:uiOptions="splitActionBarWhenNarrow" to your activity tag in theAndroidManifest.xml like this...
`<activity
android:name=".MainActivity"
android:uiOptions="splitActionBarWhenNarrow">`<br>
You can read more here and here
NOTE: It is available ONLY for handset devices with a screen width
of 400dp.
To create a custom bottom toolbar:
If you want to set it for all devices, please check my answer (find a post starting with Creating custom bottom toolbar) here:
Creating custom bottom toolbar
I've already created a simple app which should demonstrate you how to
begin
Creating a custom ViewGroup
Here's my activity_main.xml layout file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dp"
tools:context="com.example.piotr.myapplication.MainActivity">
<LinearLayout
android:id="#+id/show_pdf"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#color/primary_material_light"
android:orientation="horizontal">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_cut_mtrl_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_copy_mtrl_am_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_selectall_mtrl_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_paste_mtrl_am_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_share_mtrl_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_selectall_mtrl_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_moreoverflow_mtrl_alpha"/>
</LinearLayout>
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="75dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"/>
</RelativeLayout>
As you can see my parent ViewGroup is RelativeLayout, which simply
allows me to create a view at the bottom of screen.
Notice that I set layout padding to zero (I think: setting layout
margin to zero here is not necessary, the same effect). If you'd
change it, the toolbar won't use full width and it won't stick with
bottom of the screen.
Then I added a Linear Layout with hardcoded height which is:
android:layout_height="40dp"
I wanted it, that my bottom toolbar would take full available width so
I set it as match_parent.
Next, I added some ImageButton views with images from Android
library.
There you have two possibilities:
if you really want to have a toolbar like in above example just remove in every ImageButton view this line:
android:layout_weight="1"
After removing weights and some buttons you would get a view pretty
similar to expected:
if you want to take the full width and make every button with the same size use in your project weight as in this mine example.
Now let's go to my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.example.piotr.myapplication"
xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:windowSoftInputMode="stateVisible|adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
In that file I'd added as you can see only one additional line:
android:windowSoftInputMode="stateVisible|adjustResize">
to make sure that device keyboard won't hide my custom bottom toolbar.
From: How to add a bottom menu to Android activity
If you have any question please free to ask.
Hope it help
Hi guys i have this splash screen with the layout main.xml which contains an imageview,
here is the main.xml file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/slide11" />
</LinearLayout>
and here is my splashscreen.class file
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
new Handler().postDelayed(new Runnable() {
public void run()
Intent intent = new Intent(getApplicationContext(),content_activity.class);
startActivity(intent);
Main.this.finish(); } }, 5000);
} catch(Exception e){}
}
#Override
public void onBackPressed() {
super.onBackPressed();
} }
when i try to run this in my emulator all works fine, but when i try to run it in a device through debugging mode i don't get the image specified in the imageView, but i get a white screen for the specified amount of time.any help would be much appreciated.
//edit : i double checked the res/drawable folder and i tried primarily using png and also gave a go using .gif none worked in the device. (device micromax a110)
use this instead of your layout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/slide11" >
looks like it was because of the size of the image, when reduced worked !!
Use image as layout background :-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/slide11"
>
</LinearLayout>
This can be happening due to issue in the manifest file. Here is an example of my manifest file which has 3 activities and 1 splash screen. Hoping that this helps out.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.foodorder">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.FoodOrder">
<activity android:name=".MainActivity"></activity>
<activity android:name=".Final_activity" />
<activity android:name=".Second_activity" />
<activity
android:name=".SplashActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>