Creating bodyless activity - java

Currently I am trying to make an activity that can be moved on the screen , in other words this activity can float on the screen. I know I am missing something that should be added to achieve this functionality.
What should I do to achieve floating activity which can be moved around anywhere on the screen?

If you're looking to do something similar to the Facebook chat circles (where you have a view on top of other apps) then take a look here: http://www.cloudinfy.com/2013/06/android-chat-head-view-like-in-facebook.html
Basically you need to start a service and add a view to the window manager.
If you're looking to simply create an activity to look like a dialog then have a look here: Android Activity as a dialog
This is very similar to a normal activity but the theme is set to Theme.Dialog

There's a good solution here: http://cases.azoft.com/android-tutorial-floating-activity/
They just add an attribute to the theme of a tablet Activity:
<item name="android:windowIsTranslucent">true</item>
If any problems on KitKat devices, add some lines to the theme:
<item name="android:windowIsFloating">true</item>
<item name="android:windowCloseOnTouchOutside">false</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:backgroundDimEnabled">true</item>

Related

How do I make ImageViews appear behind System Bars?

I made this in Android Studio using a FullScreenLayout. I managed to hide the Action bar, but content is still being cutoff where the bar would've been, like the topmost alien.
I'd like the image to be displayed there too, but I haven't been able to find a solution for a FullScreenLayout.
This is the code for the styles.xml file
<resources>
<style name="Widget.Theme.SpaceInvaders.ActionBar.Fullscreen" parent="Widget.AppCompat.ActionBar">
<item name="android:background">#color/black_overlay</item>
</style>
<style name="Widget.Theme.SpaceInvaders.ButtonBar.Fullscreen" parent="">
<item name="android:background">#color/black_overlay</item>
<item name="android:buttonBarStyle">?android:attr/buttonBarStyle</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
The solutions I've seen told me to replace the ActionBar with NoActionBar, but if I do that here, Android Studio tells me that it cannot resolve symbol 'NoActionBar'.
So how do I get rid of both System Bars, and how do I make ImageViews appear where they would've been?

Fixed background while switching layouts

I got my application uploaded and I see that despite I have the same background image on all my layouts.
if I switch, the layout moves according to the animation.
Is there a way for me to set a fixed background for all my layouts?
Does it matter that I finish(); every layout before I switch to the next one?
Setting the same background to all the layouts doesn't make it fixed (it moves)
neither does creating a style like :
<style name="AppTheme.FullBackground" parent="AppTheme">
<item name="android:background">#mipmap/background</item>
</style>
and adding :
android:theme="#style/AppTheme.FullBackground"
to the manifest.
Any ideas?
If you are using all activities in your app then change all activities to fragment and just use one activity with your required image as background.
Then use just this activity for all the fragments in your app. This will not move your background image during navigating to different screens(fragments)

popup screen with background not in focus in android

I am trying to design something like the image below
I have tired PopupWindow but the background still remain in focus.
Create Custom Theme in style like this
<style name="CustomDialogTheme" parent="android:Theme.Dialog">
<item name="android:backgroundDimEnabled">true</item></style>
and call this on Dialog you want.

How can i change android actionbar picture

i am new on android and i am using android studio to develop. i want to change actionbar top right corner button image to another one but after compile to my android device the button still remain the ... but my customize image. please help!! below is my code. my public class is extend activity.
menu.xml
android:id="#+id/action_share"
android:orderInCategory="100"
android:title="Share"
android:icon="#drawable/ic_search_black"
app:showAsAction="ifRoom"
Vic3ai, That icon all the way to the right is the Action Overflow and it will always show a drop down list of action buttons that don't fit on the actionbar (either because there isn't room or because we decided to put some in the overflow on purpose).
This might give you a better idea of what the overflow is and is used for, as well as a general overview of the actionbar - http://developer.android.com/design/patterns/actionbar.html.
It sounds like what you actually want is to add an action button to your action bar. You can do that like so:
First add a new item in your menu.xml for which ever activity you want it to appear in:
<item
android:id="#+id/camera_button"
android:title="#string/camera"
android:icon="#drawable/camera_icon"
android:orderInCategory="100"
android:showAsAction="always"
/>
Here the important thing is android:showAsAction="always". This is what makes it appear as an action button on the action bar. You could also use value 'ifRoom', which does what it says on the tin: If there's room on the actionbar the button will display, otherwise it goes into the action overflow.
Now that we have the actionbutton in existence we go to our actvity.java and respond to the button:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.camera_button:
//your code here, eg:
openCamera();
return true;
// if you have other buttons, more cases would go here
}
return super.onOptionsItemSelected(item);
}
So far this should give you an Action Button on the actionbar that will run whatever could you define in your activity.java but the action overflow will still be there. The easiest way to remove it is to go back to your menu.xml and remove/change any items that would appear in the overflow.
android:showAsAction="never"
will automatically put action in to the overflow
If you have a lot of action buttons and any of them have android:showAsAction="ifRoom", you might find an overflow button on the far right again
NOTE, use app:showAsAction="always" instead of android namespace if you're using appCompat compatibility.
Hope this helps!
To change the Action Overflow Icon - default is three vertical dots - you have to add an actionOverflowButtonStyle item to your main theme declaration AND then define it in styles.xml:
<resources>
<!-- base application theme -->
<style
name="AppTheme" parent="#android:style/Theme.Holo">
<!-- include overflow style in theme -->
<item name="android:actionOverflowButtonStyle">#style/OverFlowIcon</item>
</style>
<!-- styles -->
<style
name="OverFlowIcon"
parent="#android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">#drawable/ic_search_black</item>
</style>
</resources>
Of course if you're using AppCompat themes don't forget to use atributes without the android namespace or it wont work - ie
<item name="actionOverflowButtonStyle">#style/OverFlow</item>
instead of what you see above.
Also don't forget to include your theme in application tag of AndroidManifest.xml if you change make a custom theme:
<application
android:name="com.example.android.MainApp"
android:theme="#style/AppTheme">
</application>

How can I alter colors on Theme.Holo.Dialog?

I got an activity showing as a dialog using
android:theme="#android:style/Theme.Holo.Dialog"
in the manifest file
How can I change the colors of the text and background in the dialog/activity
The simplest way to use this library for custom dialogs. But of course you can build your custom dialog yourself. You can't change the color only (for example the line) without making a custom dialog with your own resources.
Here is the source for the original holo dialog. You can reproduce this, but using the library is faster.
You have to just define your own custom style in values/styles.xml to achieve it.
Step 1- put below code in values/styles.xml file
<style name="UserDialog" parent="android:style/Theme.Dialog">
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:background">#c39797</item>
<item name="android:textColor">#E64C66</item>
</style>
Step-2 And use it AndroidManifest.xml:
android:theme="#style/UserDialog"
Note: you need to create a transparent png drawable if you want to add

Categories