Overlay an activity on another activity OR overlay a view over another - android

I have 2 classes, FirstActivity and SecondActivity.
First Activity
Intent intent=new Intent(getApplicationContext(),SecondActivity.class);
startActivity(intent);
Is it possible for SecondActivity to overlay on FirstActivity? ie. FirstActivity gets dimmed, SecondActivity gets displayed on top of FirstActivity.
If it is not possible for 2 different activities, is it possible to do an overlay for 2 views in the same activity? I hope using dialog is not the only option.

I suggest you set your second activity up as a dialog -- which will dim the background. Here is a tutorial that could be helpful:
http://developer.android.com/guide/topics/ui/dialogs.html
http://www.helloandroid.com/tutorials/how-display-custom-dialog-your-android-application
Or you can simply set the theme in the manifest as a dialog for your SecondActivity.

If you don't want to do a dialog, you can overlay views using a relative layout.
<?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="fill_parent" >
<LinearLayout android:id="#+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="some content"
android:textSize="70dp"/>
</LinearLayout>
<LinearLayout android:id="#+id/overlay"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#99000000"
android:clickable="true"
android:visibility="gone">
<EditText android:id="#+id/edittext"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="50dp" />
</LinearLayout>
</RelativeLayout>
The first LinearLayout (id/content) is your base layout where your normal content would go.
The second LinearLayout (id/overlay) is your overlay layout which you'd want to show over top of the base layout. The background color will give give you that faded out background, and you can add whatever you want to that layout to make your overlay. To show the overlay, just change its visibility from gone to visible.

In manifest file declare the secondactivity activity like this. android:theme="#android:style/Theme.Dialog".then simply call the secondactivity from firstactivity from your code.
<activity
android:name=".FirstActivity"
android:label="#string/title_activity_first" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SecondActivity"
android:label="#string/title_activity_second"
android:theme="#android:style/Theme.Dialog"
>
<intent-filter>
<action android:name="transparent.text.SECONDACTIVITY"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Second Activity xml file.you can design as your wish but for reference i have posted this.the key concept is in manifestfile (ie) how to define your secondactivity in manifest
<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" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="192dp"
android:background="#aabbcc"
android:text="Sybrant has provided Takoma with a great team which helped us from the beginning to the final stage of our product, to our fullest satisfaction. We have been able to deliver a high quality of eLearning products to our corporate customers like Nissan with Sybrant’s support”"
tools:context=".FirstActivity" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="43dp"
android:layout_marginLeft="80dp"
android:text="Button" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/button1"
android:layout_below="#+id/textView1"
android:layout_marginRight="42dp"
android:layout_marginTop="80dp"
android:text="TextView" />
</RelativeLayout>

1-Take a screenshot of the first activity.
2-(Optional) Darken, tint or blur the screenshot.
3-Then call the second activity and use the first activity screenshot as background for the second activity.

Related

Recycler View background image gets shrink when keyboard popups through editText

I have a recycler-view with a sample background in my activity but I'm stuck in an error. Whenever keyboard popups in the activity, the background of recycler-view gets shrink. How to avoid this thing. Means how to stop it from being shrinking ? Here are the images attached below.
normal Image
shrinked background
XML Code:
<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:background="#drawable/splash_bg"
tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/editText" />
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="5dp"
android:layout_marginEnd="15dp"
android:layout_marginStart="15dp"
android:layout_marginTop="5dp"
android:background="#fff"
android:hint="Your text here"
android:inputType="text"
android:padding="12dp"
android:textSize="24sp" />
</RelativeLayout>
In the tag of the recyclerview container activity declared in manifest add
android:windowSoftInputMode="stateHidden|adjustNothing"
like
<activity
android:name=".YourActivityName"
android:windowSoftInputMode="stateHidden|adjustNothing" />
add the image to your background of layout, not in recyclerview. And also recyclerview's item should have no background color except its necessary to widgets.
Set attribute android:windowSoftInputMode to be "adjustPan" in your AndroidManifest.xml under your activity:
<activity
android:name=".YourActivityName"
android:windowSoftInputMode="adjustPan" />

Why keyboard is overlap on the AutoCompleteTextView when inside ScrollView

I have a simple android layout and code, but the keyboard always overlap my AutoCompleteTextView when I click it.
Note : The AutoCompleteTextView when inside ScrollView.
Note : platform is 6.0.1
package com.example.jason_wu.search;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.AutoCompleteTextView;
public class Main2Activity extends AppCompatActivity {
private AutoCompleteTextView mAtv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
mAtv = (AutoCompleteTextView) findViewById(R.id.location_auto_complete);
//issue 1
//mAtv.setBackground(getDrawable(R.drawable.search_input_focus));
//issue 2
mAtv.setHeight(300);
}
}
and my AndroidManifest.xml here:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.jason_wu.search">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name="com.example.jason_wu.search.Main2Activity"
android:windowSoftInputMode="adjustPan"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Layout.xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/scrollView" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="800dp"
android:text="Large Text"
android:id="#+id/textView"/>
<AutoCompleteTextView
android:id="#+id/location_auto_complete"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="#+id/textView"
android:background="#color/transparent"
android:dropDownAnchor="#+id/location_auto_complete"
android:dropDownHeight="wrap_content"
android:dropDownVerticalOffset="1dip"
android:fontFamily="sans-serif-light"
android:hint="#string/new_notification_location_hint"
android:imeOptions="actionSearch"
android:inputType="textUri"
android:dropDownSelector="#color/location_bg_select"
android:popupBackground="#color/location_bg_notselect"
android:singleLine="true"
android:textColor="#FFFFFF"
android:alpha="0.2"
android:textColorHint="#999999"
android:textCursorDrawable="#null"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="100dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/textView2"
android:layout_below="#+id/location_auto_complete" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
See
try this attribute to the activity in the AndroidManifest.xml
android:windowSoftInputMode="stateHidden|adjustPan"
it should look something like this.
<activity
android:name="com.myexample.TestActivity"
android:label="#string/login_screen"
android:screenOrientation="portrait" // well you can change the orientation if you want
android:windowSoftInputMode="stateHidden|adjustPan" />
the attribute you want to play with is this windowSoftInputMode try different values as you may require different output after certain time.
adjustPan
The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.
adjustResize
The activity's main window is always resized to make room for the soft keyboard on screen.
stateHidden
The soft keyboard is hidden when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity.
you can find more details on activity-element documentation
Update
I have written something that might help you, layout is available on the layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context="activities.list.first.TestLayoutActivity">
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.6"
android:orientation="vertical">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.4"
android:orientation="vertical">
<AutoCompleteTextView
android:id="#+id/TestLayoutActivity_autoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:completionThreshold="1"
android:drawableLeft="#android:drawable/ic_menu_search"
android:text="" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
AndroidManifest.xml
<activity
android:name="activities.list.first.TestLayoutActivity"
android:label="#string/title_activity_test_layout"
android:windowSoftInputMode="stateHidden|adjustPan"
/>
Code is on the code
String[] list = {"match1", "match2", "match3",
"match12", "match11", "match8", "match7", "match4",
"match13", "match10", "match9", "match6", "match5",};
AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.TestLayoutActivity_autoCompleteTextView);
ArrayAdapter<String> adapter
= new ArrayAdapter<String>(getApplicationContext(), R.layout.simple_list_item_1, list);
autoCompleteTextView.setAdapter(adapter);
Before
After
[
Try limiting the dropdown items to show
One way is you can Limit the dropdown items to show. But there's no such proper way of it to show number of maximumSuggestions option, But the trick you can apply is Get the height of one of the rows and multiply it (number of rows to show) times and use setDropDownHeight() to set its height.
There is a method setDropDownHeight of AutoCompleteTextView class. You can see them and use.
If you are confused or not sure of height of suggestions items you can customize this. Have a look how to set custom height.
The keyboard behavior is that scroll the view to close the bottom of text area.
Finally, we have to use android:gravity="bottom" attribute to solve UI issue, but we need to consider the UX, ex: Hint.
So, The solution is to listen onClick() and For keyboard issue, we have to use dynamic method to set the gravity.

How to move the layout above of soft keyboard when it is shown

I have a simple layout for my activity:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:id="#+id/editTextName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/buttonCancel"
android:layout_alignParentTop="true" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="cancel" />
</RelativeLayout>
and when I touch on EditText soft keyboard appears but my button hides beyond the keyboard !
but I wanna the Button move up (above of) the keyboard.
I added this line of code to AndroidManifest but nothing changed.
<activity
android:name=".Activity"
android:windowSoftInputMode="adjustPan|adjustResize">
</activity>
According to the official documentation adjustPan and adjustResize have an opposite behaviour and therefore I don't think they should be used together. Try just android:windowSoftInputMode="adjustResize" , worked for me.

Android: EditText in ScrollView goes of the screen when kayboard appears

I am trying to create a login screen. I have used ScrollView to hold input fields. I have following xml:
<RelativeLayout ... >
<RelativeLayout
android:id="#+id/top_menu" ... >
<ImageButton ... />
<com.neopixl.pixlui.components.textview.TextView... />
</RelativeLayout>
<ScrollView
android:id="#+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/top_menu"
android:overScrollMode="always">
<LinearLayout
android:id="#+id/login_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<com.neopixl.pixlui.components.edittext.EditText
android:id="#+id/user_name_email"
android:layout_width="match_parent"
android:layout_height="#dimen/input_height_size"
android:layout_marginEnd="20dp"
android:layout_marginStart="20dp"
android:background="#drawable/edit_text_strock"
android:hint="#string/user_Name_Email_EditText"
android:maxLines="1"
android:paddingLeft="10dp"
android:paddingStart="10dp"
android:textColor="#color/White"
android:textColorHint="#color/White"
android:textSize="#dimen/register_input_text_size"
pixlui:typeface="MuseoSans.otf"/>
<com.neopixl.pixlui.components.edittext.EditText.... />
<com.neopixl.pixlui.components.button.Button... />
<com.neopixl.pixlui.components.textview.TextView... />
<com.neopixl.pixlui.components.textview.TextView... />
<com.neopixl.pixlui.components.textview.TextView... />
<com.neopixl.pixlui.components.button.Button... />
</LinearLayout>
</ScrollView>
</RelativeLayout>
You can see full xml here.
When I click on EditText user_name_email, it goes off the screen.
Before click:
After click:
I have tried scrollTo(x, y) and smootScrollTo(x, y) bu they didn't work.
How can I fix it?
UPDATE:
adjustPan works but I want it to work with adjustResize.
Is it possible?
Use the following line in the manifest file, for the activity you need the change.
android:windowSoftInputMode="adjustPan"
Use it as shown below:
<activity
android:name=".ActivityName"
android:label="title_for_activity"
android:windowSoftInputMode="adjustPan" >
</activity>
Hope this helps.
add this to manifest file:
android:windowSoftInputMode="adjustPan"
in the targeted activity tag.

How do I make an empty view inside ListFragment resize automatically at all times?

More specifically, I'm using SherlockListFragment inside a ViewPager and the following layout
(full source):
<?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="fill_parent" >
<RelativeLayout
android:id="#+id/filter_bar"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_alignParentBottom="true"
...
/>
<ListView
android:id="#android:id/list"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignWithParentIfMissing="true"
android:layout_above="#+id/filter_bar"
... />
<TextView
android:id="#android:id/empty"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignWithParentIfMissing="true"
android:layout_above="#+id/filter_bar"
android:text="..."
android:visibility="invisible"
.../>
</RelativeLayout>
When I open the application I see this:
That looks fine. Then I connect and open a filter, it's empty for now
Note that ListView gets resized just fine. Now I type in the filter to filter out everything:
Whoops! Action bar disappears from the display! However, if swipe back and forth through the ViewPager and do it again, everything becomes fine (and stays fine):
What could I do to make the empty view behave normally, just like ListView does?
set windowSoftInputMode to the activity declaration in AndroidManifest.xml . Something like this
<activity
android:name=".controll.MyActivity"
android:label="#string/title_activity_my"
android:windowSoftInputMode="adjustResize"/>

Categories

Resources