Achieving modal view feature in Android - android

My goal is to set a modal view in my Android application. I would like to open one view whose background would be transparent so the user can see the view behind.
I've heard about using transparent activity but this might freeze the activity behind, ain't it ?
I would like some kind of reusable stuff since this view will call in more than one activity.
Thanks

You can make an Activities background transparent using this style:
<style name="TransparentActivity" parent="android:Theme.Black.NoTitleBar.Fullscreen">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">#android:style/Animation</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowFullscreen">true</item>
</style>
Declared in the manifest like so:
<activity
android:label="#string/app_name"
android:name=".activity.DialogActivity"
android:theme="#style/TransparentActivity" >
I then use this as the layout for my dialogue:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/containerPageContainer">
<FrameLayout android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#drawable/panel_picture_frame_bg_focus_blue"
android:layout_gravity="center"
android:id="#+id/dialog"/>
</FrameLayout>
You can either inflate other layouts and add it to #+id/dialog or use fragments (depending on how brave you are).
Hope that helped!

Perhaps you could use a Dialog? You can use a custom content view to display whatever you want, and use setCancelable(false).

Related

Custom style attributes for SwitchPreferenceCompat (support v7)

I am trying to add some space to the the top of my SwitchPreferenceCompat which is inside of a PreferenceFragmentCompat. Basically I just need some room between it and the top Toolbar, either by expanding its height or with a padding gap without adding a white space that will interfere with the elevation shadow of the Toolbar. I believe I can achieve this by adding a custom style to the SwitchPreferenceCompat, but I am having trouble getting that to work.
Here is what I have tried:
In my styles.xml-
<style name="SwitchPreferenceNew" parent="Preference.SwitchPreferenceCompat.Material">
<item name="android:paddingTop">20dp</item>
</style>
In my app_preferences.xml-
<android.support.v7.preference.SwitchPreferenceCompat
style="#style/SwitchPreferenceNew"
android:defaultValue="false"
android:icon="#drawable/ic_power_settings_new_black_48dp"
android:key="prefsActivate"
android:summary=""
android:title="Activate reminders" />
I think I am just not overriding the style correctly, but I am having trouble finding out how to do it with the SwitchPreferenceCompat. Thank you in advance!
I know this is late but i get result from following code:
my app theme:
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="preferenceTheme">#style/my_preference_theme</item>
</style>
my preference theme:
<style name="my_preference_theme" parent="#style/PreferenceThemeOverlay">
<item name="switchPreferenceCompatStyle">#style/preference_switch_compat</item>
</style>
in my PreferenceSwitchCompat i used layout property and you should create new layout for your view
<style name="preference_switch_compat">
<item name="android:layout">#layout/switch_layout</item>
</style>
this is here you must customize your view:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.SwitchCompat
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/switchWidget"
android:background="#f00"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
hope to help to someone.

how to show an activity over another on half of the screen in the right position?

I am new in android.
I have 2 activities and I want to show the second activity over the first one, but the second activity has a layout:width : 250dp and layout height is fill-parent(fill the screen) and start from the right of the screen.
How can I do that?
I want something like this
screen
You can make a transparent theme for the second activity so it is shown as a floating window. Then for the second activity, restrict the width of the view layout inside a Viewgroup that defines the position.
Here is my style definition for the Transparent theme. Setting this, f.e. in the Manifest <activity> declaration, makes it possible to achieve a floating activity on top of the other:
<style name="Theme.Transparent">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
The layout is like this, for example, showing a CardView from the right (end):
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:card_view="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.CardView
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="top|end">
</android.support.v7.widget.CardView>
</FrameLayout>
I wonder why you would fixate the width to 250, what would happen on bigger/smaller devices? Maybe better to define a margin or padding...?

AppCompat Dialog theme's margins and background with circular reveal

I am having some difficulties..
I want to mimic Floating Search Widget as seen in Google I/O 2015 app - seen bellow.
So far I managed to put my second(search) activity into a dialog with Theme.AppCompat.Light.Dialog theme. I followed the steps shown here https://stackoverflow.com/a/32199671/2674529 to ger circular reveal effect working.
Second activity style is defined in Theme.Transparent
<style name="Theme.Transparent" parent="Theme.AppCompat.Light.Dialog">
<item name="android:windowIsTranslucent">false</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="windowNoTitle">true</item>
</style>
Note: Greenish color is green color with alpha and is the background of the root layout of the second activity.
The problem is transparency of the dialog's background.
If I comment out the
<item name="android:windowBackground">#android:color/transparent</item>
from the theme, then the dialog's background is whitish - as seen bellow.
If I uncomment the line I get a "dialog" without any border nor margin - seen bellow.
Does anyone have any ideas? Thanks
PS. xml of the dialog/activity
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#8800FF00">
</FrameLayout>
</android.support.v4.widget.DrawerLayout>

dynamically setting alpha to background image of the layout is not taking effect

I'm developing for api 15. I have a layout with a background image and a button. When the button is pressed background image should change alpha to 150. But it isn't taking effect. Do I have to somehow force update on layout so that it does take effect?
Here is my xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/wall1Layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/wall1withkey"
tools:context=".FireRoomActivity" >
<Button ...
/>
</RelativeLayout>
And in main activity there is a method that supposed to respond to onClick from the button:
public void buttonClicked(View v)
{
findViewById(R.id.wall1Layout).getBackground().setAlpha(180);;
}
So the image wall1withkey should change alpha to 180
When i tried to create translucent background i used my own custom Theme.
styles.xml
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
Then you have to set this Theme.Transparent to your activity in AndroidManifest.xml
<activity
android:name="com.example.TransparentActivity"
android:theme="#style/Theme.Transparent" >
</activity>

Disable Android list view 'blue' background

When I click on the list item in Android, I always get a blue background. Event if I use a custom layout, when I click, maybe 2-5dp space around my layout is blue. Also, the text views get darker. How can I disable any changes in view when clicking on the list item?
I know its kind of late, but one can also use the setSelector method of the listview and set it to android.R.color.transparent. You can also use android:listSelector in the layout file to achieve the same result.
Create custom theme for your application in /res/values/themes.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- application theme -->
<style name="CustomTheme" parent="android:style/Theme.Light">
<!-- widget styles -->
<item name="android:listViewStyle">#style/ListView</item>
</style>
<!-- list view -->
<style name="ListView" parent="#android:style/Widget.ListView">
<item name="android:background">#ffffff</item>
<item name="android:cacheColorHint">#ffffff</item>
<item name="android:divider">#cccccc</item>
<item name="android:dividerHeight">1px</item>
<item name="android:listSelector">#drawable/list_selector_background</item>
<item name="android:fadingEdge">none</item>
</style>
</resources>
In your AndroidManifest.xml specify the theme:
<application
...
android:theme="#style/CustomTheme" >
You can simply set the android drawSelectorOnTop attribute to false on your ListView and there will not be any background when you click on an item.
Eg:
<ListView android:layout_width="fill_parent" android:layout_height="fill_parent"
android:drawSelectorOnTop="false"/>
Use this
<ListView
android:listSelector="#android:color/transparent"
android:cacheColorHint="#android:color/transparent"
/>
For more details you can visit here
http://developer.android.com/reference/android/widget/ListView.html
I did it Like this:
<ListView
android:listSelector="#android:color/transparent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>

Categories

Resources