android - How to create an activity that resembles a dialog but has some specific features like scrolling off the screen -


i'm trying create activity looks dialog. these features want achieve:

  1. doesn't take entire screen
  2. you can see previous activity in background
  3. the background should darken
  4. parts can scroll off screen
  5. it should dismissed when clicking on background (where previous activity visible)

when searching using activities dialogs people seem suggest using dialog style activity, example theme.appcompat.light.dialog.

<style name="activitydialog2" parent="theme.appcompat.light.dialog">     <item name="colorprimary">@color/primary</item>     <item name="colorprimarydark">@color/primary_dark</item>     <item name="coloraccent">@color/accent</item>      <item name="android:windownotitle">true</item> </style> 

so tried , ended can seen in these two screenshots.

so 1, 2 , 5 have been achieved enough. 3 , 4 not yet. 3 should easy enough, can't figure out how 4 style.

because couldn't figure out opted option: changing normal activity style want.

<style name="activitydialog1" parent="theme.appcompat.light.noactionbar">      <item name="colorprimary">@color/primary</item>     <item name="colorprimarydark">@color/primary_dark</item>     <item name="coloraccent">@color/accent</item>      <item name="android:colorbackgroundcachehint">@null</item>     <item name="android:windowcontentoverlay">@null</item>     <item name="android:windowbackground">@android:color/transparent</item>     <item name="android:windowistranslucent">true</item> </style> 

i ended can seen in these two screenshots. dig style of (except opening animation). i'm running issue. can't seem dismissed when clicking background. idea had setting click listener scrollview , calling onbackpressed(), won't register.

does have idea how can achieve properties i'm aiming for?

i've created repository sample application current ideas , implementations here interested.

edit: have managed implement method dismiss activity. i've added linearlayout scrollview setting match_parent , i've set scrollview fill viewport. next had set clickable false on cardview , able add listener linearlayout dismiss activity.

so trying isn't practice, trying use activity dialog. have created fragments this, dialog fragments. fragments ui components own functionality part of activity.

more on here: http://developer.android.com/guide/components/fragments.html

okay create new fragment extends dialog fragment so:

public class newdialogfragment extends dialogfragment {      public newdialogfragment() {        //constructor     }      @override     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {         view view = inflater.inflate(r.layout.fragment_new_dialog, false); //inflate xml layout          //put code fragment here                  return view;     } } 

the xml layout works same way in activity should able use same layout file.

and in main activity launching dialog in:

//on button click or whenever want launch newdialogfragment fragment = new newdialogfragment(); fragment.show(getfragmentmanager(), "dialog"); 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -