creating a new transparent activity - android

im trying to play a video or show a picture on the phone while still being able to control the phone.
the only thing ive managed to do so far is to start a new transparent activity.
that enables me to show whatever i would like. but i cannot control the phone behind the pic/video.
this is my code:
<activity
android:name=".VideoPopActivity"
android:label="#string/app_name"
android:theme="#style/Theme.Transparent" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and in the 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:background">#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>
<item name="android:windowFrame">#null</item>
open to new suggestion aside from this "trick".....

No, you cannot control an inactive Activity, specifically one that is beneath the active one.
What you'll want to do is create a RelativeLayout that contains your transparent picture as well as the main layout. This will layer them on top of each other. Make sure both are match_parent for both width and height.
<RelativeLayout
... >
<LinearLayout
... >
<!-- This is your main layout -->
</LinearLayout>
<ImageView
android:visibility="gone"
... /> <!-- Your picture, invisible by default -->
</RelativeLayout>
Or, instead of an ImageView, make another layout, in which you can place your video/image content.

This is way to to make activity transparent, however to get more pleasing view, you should make your activity not apaoque, not transparent, as it will give a mirror like or water like view..
you could use,
You should create opaqueStyle.xml in the drawable folder and set your main layout's background as the opaqueStyle.xml..
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="1dp" android:color="#FFFFFFFF" />
<solid android:color="#30646464" />
<corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp" android:topRightRadius="7dp"/>
</shape>
Here in <solid android:color="#30646464" /> this line, "#30646464", 30 is for opacity, you can increase or decrease its opacity and else six digits are the color, you can adjust it for urself..

Related

Set the background image as device width and device height in xml file

I want to display the bg image as the splash screen. So how can I set the image to device screen width and device screen height. Can I do it from the xml file below (this xml file is inside drawable folder) . I tried to put fill_parent or match_parent in the width but it gives error. Is there any way to do it?
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#color/white"/>
<item
android:drawable="#mipmap/bg"
android:gravity="center"
android:width="300dp"
android:height="600dp"/>
</layer-list>
Set the image to the ImageView in the splash screen and set the scaleType attribute of the ImageView as "fixXY".
Replace android:drawable="#color/white with background drawable.
<!-- in your_splash_screen.xml -->
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/your_background" />
</layer-list>
<!--in values.xml -->
<style name="AppTheme.SplashScreen" parent="AppTheme">
<item name="android:windowFullscreen">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowBackground">#drawable/your_splash_screen</item>
</style>
<!--in AndroidManifest.xml -->
<activity
android:name=".SplashActivity"
android:theme="#style/AppTheme.SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Drawable as background of splash theme doesn't keep ratio

In my application, I'm trying to set the splash theme with a drawable background. It works correctly if I use a small image, but when the image is bigger then the screen size, it doesn't work anymore.
The image is correctly scaled horizzontally, but the height isn't, as follows:
I tried every scaletype and gravity, what else can I do?
this is my Theme:
<style name="SplashTheme" parent="AppTheme">
<item name="android:windowBackground">#drawable/background_splash</item>
</style>
This is my background_splash.xml
<item android:drawable="#android:color/white" />
<item
android:left="50dp"
android:right="50dp"
>
<bitmap android:src="#drawable/logo_splash"
android:gravity="center|clip_horizontal"
android:scaleType="centerInside"
/>
</item>
and this is my manifest (relevant code):
<activity
android:name=".activities.SplashScreenActivity"
android:configChanges="orientation|screenSize"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Any idea?
You can use a layer-list like this in your background_splash.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#android:color/white"
android:gravity="fill" />
<item
android:drawable="#drawable/logo_splash"
android:gravity="center" />
</layer-list>
This will center your image on the screen and the left space will be filled by the white background color.
Maybe you have to add the image in different sizes like you can read here:
https://developer.android.com/training/multiscreen/screendensities#TaskProvideAltBmp
If you do that you can access the image with the same name. It will look like this your project structure:
If you want to remove the action and status bar in your splash screen, you can add the following line to your SplashTheme:
<item name="android:windowFullscreen">true</item>

How do I change the color behind the actionbar which appears when using rounded top corners?

I've followed Googles theme guide when customising the Actionbar. I´ve also added rounded top corners on the ActionBar. The problem is a white color appearing behind the corners where they are rounded.
This is my activity main.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"
android:background="#000000"
android:orientation="vertical" >
</RelativeLayout>
My styles.xml
<style name="AppBaseTheme" parent="android:Theme">
<item name="android:windowBackground">#color/black</item>
</style>
This is my actionbar_theme.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#ffc71e"
android:endColor="#d09e07"
android:type="linear"
android:angle="270"/>
<stroke
android:width="1px"
android:color="#333" >
</stroke>
<corners
android:topLeftRadius="7dp"
android:topRightRadius="7dp">
</corners>
</shape>
How do I change the background of the base application. I want it black.
Thank you.
I had the same problem, and this solution works for me. Just change the colorBackground of your activity theme's style.
<item name="android:colorBackground">#android:color/black</item>
This is my activity in manifest file:
<activity
android:name=".MainActivity"
android:label="#string/title"
android:theme="#style/MyTheme"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
My theme style xml file, styles.xml
<resources>
<style name="MyTheme" parent="Theme.AppCompat.Light">
<item name="android:colorBackground">#android:color/black</item>
</style>
</resources>

ActionMode custom background

How can we change the layout or background of an ActionMode ? there is methodactionMode.getCustomView();but always returns null . is there any suggestion?
You can change it through styles.xml with this attribute
<item name="android:actionModeBackground">#drawable/actionbar_background</item>
<item name="actionModeBackground">#drawable/actionbar_background</item>
ASAIK changing it programmatically is not yet supported
I wanna make more clearer this answer. First create custom background "storage_list_header_shape.xml" in your drawable folder.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="270"
android:startColor="#android:color/holo_orange_light"
android:centerColor="#android:color/holo_orange_dark"
android:endColor="#android:color/holo_orange_light" />
<size android:height="3dp" />
</shape>
Second, create custom style in your style.xml
<style name="customActionModeTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionModeBackground">#drawable/storage_list_header_shape</item>
</style>
Third, call the style in your manifest.
<activity
android:name="com.javacafe.activities.Main"
android:launchMode="singleTop"
android:screenOrientation="sensorLandscape"
android:theme="#style/customActionModeTheme" >
</activity>
if you want to change the background of an ActionMode,you should use the actionMode.setCustomView(View yourView),then you can transfer the yourView variable to the method.

Setting image source for ToggleButton

I have a 30px x 30px png file that i would like to use as an android:src rather than an android:background. By using it as the background, and mentioning "wrap_content" for both the height and the width, the final result looks more like a 45px x 45 px.
Ideally, what i need is a mix of ImageButton and ToggleButton. I would like to have the feature of setting an android:src of ImageButton and the feature of toggling where states are saved automatically for me.
Any solution or workaround?
TIA.
Hi, It does not seem to help creating another style. The src still appears much bigger that it's original 30px x 30px.
In main.xml:
<ToggleButton android:id="#+id/blah"
style="#style/myToggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ToggleButton>
In Styles.xml
<style name="myToggle">
<item name="android:textOn">""</item>
<item name="android:textOff">""</item>
<item name="android:disabledAlpha">?android:attr/disabledAlpha</item>
<item name="android:background">#drawable/my_btn_toggle_bg</item>
</style>
In my_btn_toggle_bg.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/myBackground" android:drawable="#android:drawable/btn_default_small" />
<item android:id="#+id/myToggle" android:drawable="#drawable/my_btn_toggle" />
</layer-list>
In my_btn_toggle.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false" android:drawable="#drawable/pausebutton" />
<item android:state_checked="true" android:drawable="#drawable/playbutton" />
</selector>
playbutton.png and pausebutton.png are 30px x 30px each. But they appear much bigger when i see it laid out on the device
You can make the toggle button look like whatever you want. You just need to create a style. Have a look in the /platforms//data/res/values/styles.xml and search for Widget.Button.ToggleButton It looks like this:
<style name="Widget.Button.Toggle">
<item name="android:background">#android:drawable/btn_toggle_bg</item>
<item name="android:textOn">#android:string/capital_on</item>
<item name="android:textOff">#android:string/capital_off</item>
<item name="android:disabledAlpha">?android:attr/disabledAlpha</item>
</style>
So if you go find the btn_toggle_bg drawable you find this:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+android:id/background" android:drawable="#android:drawable/btn_default_small" />
<item android:id="#+android:id/toggle" android:drawable="#android:drawable/btn_toggle" />
</layer-list>
Which shows you that it uses the standard Button background and a drawable called btn_toggle for the src. btn_src.xml looks like this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false" android:drawable="#drawable/btn_toggle_off" />
<item android:state_checked="true" android:drawable="#drawable/btn_toggle_on" />
</selector>
Which are the two drawables that are used to show the state of the button. They are actually called btn_toggle_{on/off}.9.png since they are 9 Patch images so they stretch to match the button size.
I figured out how to do this (centering a smaller background image inside a large ToggleButton) using ScaleDrawable:
Set your ToggleButton to use a selector Drawable, as normal:
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:variablePadding="true">
<item android:drawable="#drawable/ic_star_selected_centered"
android:state_checked="true" />
<item android:drawable="#drawable/ic_star_default_white_centered"
android:state_pressed="true" />
<item android:drawable="#drawable/ic_star_default_black_centered" />
</selector>
Then, make a ScaledDrawable for each of the items' drawables above, which points to your ACTUAL image file. e.g. ic_star_selected_centered.xml:
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/ic_star_selected"
android:scaleGravity="center"
android:scaleHeight="100%"
android:scaleWidth="100%"
/>
Finally, there is a bug in Android that makes any ScaledDrawables invisible at first, until you set their level. So when inflating your view, call setLevel() from 1-10000 (1 is smallest scale, 10000 is full-sized):
StateListDrawable star = (StateListDrawable) myToggleButton.getBackground();
star.setLevel(5000); // centers the image at half size. shame on Android for using magic numbers!
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<inset android:insetLeft="15dp" android:insetRight="15dp" android:insetTop="15dp" android:insetBottom="15dp">
<bitmap android:src="#drawable/ic_star_selected_centered" />
</inset>
</item>
<item android:state_pressed="true" >
<inset android:insetLeft="15dp" android:insetRight="15dp" android:insetTop="15dp" android:insetBottom="15dp">
<bitmap android:src=" android:src="#drawable/ic_star_default_white_centered" />
</inset>
</item>
<item >
<inset android:insetLeft="15dp" android:insetRight="15dp" android:insetTop="15dp" android:insetBottom="15dp">
<bitmap android:src="#drawable/ic_star_default_black_centered" />
</inset>
</item>
</selector>
In addition to what #caseyB had to say (look at the comments), i had to change the theme of the activity to achieve the intended effect. I think this is an issue on HoneyComb Xoom and may not be seen on phones.
Thanks for everyone for looking at my question and helping.
"Quick and dirty" way of achieving this is to use relative layout and place your ImageView on top of the ToggleButton. Set android:layout_centerInParent="true" and set your onClick listener on the toggle
Said that - the other solution by CaseyB (customizing background files) is the right approach

Categories

Resources