I would like to obtain the same effect as when a modal dialog is displayed, i.e. dimmed background, can't interact with it, but to have a layout element, or more, active "on top" of the rest. For example: I tap on an icon and a panel with detailed information appears from the left, and you can do some stuff on that panel, the rest of the screen is dimmed, inactive. How can I do this? Thanks.
You can start a new Activity with the background set to transparent on some elements, for example:
<ScrollView
android:gravity="left"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/transparent">
There is also an example of a TranslucentActivity in the Android API Demos:
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/TranslucentActivity.html
Related
Is it possible to set the visibility of the MainActivity page in android to invisible or make it transparent may be? I have tried setting the visibility to invisible and also made height width as 0dp but this still shows the mainactivity with a white background and blue header.
What I am trying to achieve is, I am opening a floating window which is draggable on click of a button in the mainactivity, but I want to directly open the floating window by triggering the button click from the code itself. This works but the mainactivity still shows up for a second before the floating window is opened. I want to make the mainactivity page invisible or transparent so the mainactivity page is not noticeable.
Here is the XML of mainactivity.xml ,
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="0dp"
android:layout_height="0dp"
android:visibility="Invisible"
android:background="#color/material_on_primary_disabled"
tools:context="com.example.widget_android.MainActivity">
<Button
android:id="#+id/open_widget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="Open Widget" />
on click of open_widget(which is triggered from code rather than the user having to click on it) the floating window is opened up.
I want to take the user directly to the floating window rather than the landing page which is the mainactivity page.
Here is what is happening on the backend java code
findViewById(R.id.open_widget).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startService(new Intent(MainActivity.this,WidgetService.class));
finish();
}
});
findViewById(R.id.open_widget).performClick();
The reason you get a white screen is because that is the default behaviour. You've tried to put an invisible, transparent, or non-existing (size of 0 pixels) View on top of the default View, so you are still seeing the default View. What you need to do is to replace the default View with a transparent View.
See How do I create a transparent Activity on Android? for information on how to get a transparent Activity.
This question already has answers here:
Bottomsheet with edit text moved up by keyboard
(2 answers)
Closed 2 years ago.
I am using a BottomSheetDialogFragment which contains:
- A RecyclerView with a list of comments made by users
- A EditText at the bottom, where users can write a new comment and post it
When the user taps on the EditText, the keyboard shows up from the bottom.
What i want is the keyboard to push ONLY the EditText, so that the user can see what he's typing, but not push the whole BottomSheetDialogFragment.
You can see the desirable behaviour in the Facebook app for example.
I have tried setting different values for setSoftInputMode but all i can achieve is either to move the whole BottomSheetDialogFragment, or to move nothing (leaving the EditText covered).
The easiest way to do this is to not use a BottomSheetDialogFragment but instead to use a regular fragment that covers the entire window or an activity. Fragment or Activity; whichever you prefer doesn't matter as long as you're taking up the whole screen.
When the on-screen keyboard appears, the activity window (by default) resizes to make way for the on-screen keyboard.
Since a BottomSheetDialogFragment has it's gravity set to bottom, when the activity window resizes, it pushes the bottom sheet and all of it's contents upwards.
Here's an example of the simplest layout that can achieve what you're going for
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="#80000000" />
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
First is a view with a constant height which imitates the dark area outside of a dialog. No matter how the window resizes this will always be 80dp.
Second is the RecyclerView which resizes based on the remaining available space the LinearLayout has. Pay attention to the attribute android:layout_weight.
Third is EditText which has a constant height of wrap_content. Again No matter how the window resizes this will always be the same height. Since the RecyclerView will take up as much space as it can, this EditText will remain at the bottom of the screen.
Once the window resizes due to the on-screen keyboard appearing, the LinearLayout will resize and recalculate it's children's sizes. Since the View and the EditText has a constant height it will have to make the RecyclerView smaller making it appear like the EditText moved upwards.
You don't have to use a LinearLayout to do this, you can achieve the same effect with any other layout. The key point here is to use a layout that takes up the whole screen.
let's say I have a view that is made up of 2 layers -> top layer and bottom layer. I place them both in a frame layout.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- bottom layer -->
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/some_image_you_shouldnt_shrink"/>
<!-- top layer -->
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/somewhat_transparent"/>
</FrameLayout>
now, presumably, when i tap on the editText, the keyboard will pop up, and shrink the size of the edit text. However, it seems that the bottom layer is ALSO getting resized. How do i prevent this bottom layer from getting resized?
Note: the framelayout is in a fragment, and the activity that holds this fragment must declare android:windowSoftInputMode="adjustResize".
EDIT*********
Just to clarify, i want the editText layer to adjust as high as the keyboard needs to. however, i don't want the image behind it to adjust at all
i only have 1 activity that handles these similar types of fragments.
You can't prevent a single view from resizing if you set android:windowSoftInputMode="adjustResize". But if you just want to set a non-resizing background, there is a work-around. Instead of setting the background image in the ImageView through XML, add this in your onCreate() method
getWindow().setBackgroundDrawableResource(R.drawable.some_image_you_shouldnt_shrink);
try this in the manifest
android:windowSoftInputMode="stateVisible|adjustPan"
Good day (or evening, or night)
I'm developing an app for android and I'm very curious about one thing. I have an activity, where user chats with another, like "im" chat. There are an EditText on the bottom and some kind of actionbar on the top. What I need is when user enters a message and the software keyboard is on screen, my activity should move up, but the actionbar should still be "glued" to the top of the screen, because it has some valuable controls on it.
Again, that's not an ActionBar, but just a 48dp height layout in a parent vertical linear layout. So I need to know is there an easy way to prevent it from moving to the top, when the layout moves off the screen.
I tried to put everything in a FrameLayout and put this bar on top of it, but on keyboard opens it goes off the screen too...
On you Activity at AndroidManifest you should put this: android:windowSoftInputMode="adjustResize"
Use something like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.myapp.MyActionBar
android:layout_width="match_parent"
android:layout_height="48dp"/>
<LinearLayout
android:id="#+id/mylayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1dp"/>
<!-- Add your edittext and button -->
</LinearLayout>
This will make sure the actionbar and edittext + button are allways on screen, and the mylayout takes up the rest of the screen. When your keyboard is shown, the mylayout will shrink.
Try adding android:windowSoftInputMode="adjustResize" to your activity in the manifest. This tells Android to completely resize your layout when the keyboard comes up, rather than pan it. Note that if there isn't enough room for the entire layout this still won't work. But you ought to be able to make it work if your top level layout is a RelativeLayout, with the edit text set to align bottom, the top bar to align top, and the middle section to fill_parent and be above the edit text and below the bar.
use a RelativeLayout as your base Layout and add android:layout_alignParentTop="true" to your action bar to keep it up
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/action_bar_layout"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentTop="true" >
</LinearLayout>
<TextView
android:id="#+id/text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
I have a rather trivial question, but I thought I'd give it a shot. I'm writing an android app and I have a viewgroup form that is loaded from a web server. While the internet access is running, I used to pop up a dialog box with a progress bar. I decided it would look less clunky if I swtiched to the nice small indeterminate progress bar in the title bar.
The title bar option does look less busy, except that the form items (textviews, buttons etc) are all enabled during the retrieval. I then used a recursive routine to disable all the views in the viewgroup, but that again looks ugly - the greyed out textviews (2.3.3) look gross, especially the one with the focus with the orange bar around it. If I pop up a progress bar, the underlying view looks nicely disabled - the window behind is simply slowly dimmed down. From a visual point of view, it much more obvious that we're waiting for something to occur when the entire window is dimmed rather than being faced with a bunch of disabled controls.
Is there a call I can make to disable a view in a similar way the OS does when a progress bar or other window is overlapped on top? This would give me the best of both worlds.
I guess the other option is to set the view to invisible during the access, but I got curious because I can see the OS doing exactly what I want when I use the popup.
I figured out how to do this using a relative layout with a progress dialog wrapped in a frame layout overlapping the main view. When I do my network get, I set the visibility of the frame layout to visible with the background set to translucent, and disable the controls in the underlying view. Works pretty well.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ScrollView
android:id="#+id/itemView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ScrollView>
<FrameLayout
android:id="#+id/itemProgress"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#55000000"
android:visibility="gone"
>
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center|center_vertical"
android:indeterminateOnly="true"
/>
</FrameLayout>
</RelativeLayout>