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.
Related
I want to have a background color that changes color according to the state of the view.
I tired creating it exactly like the example from Google (except I'm using colors from my resources instead of hardcoding the hex values :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:color="#color/transparent" />
<item
android:color="#color/gray_3"
android:state_selected="true" />
</selector>
(this is located in res/color)
then I set this as a background to my view.but when I run the code, I get a crash with this error:
Binary XML file line #3: <item> tag requires a 'drawable' attribute or child tag defining a drawable
It's telling me that the "item" tag in my selector needs drawable, not color to define the color.
when I change it to a drawable, as such:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable ="#color/transparent" />
<item
android:drawable ="#color/gray_3"
android:state_selected="true" />
</selector>
that crash goes away, but Android Studio gives me a lint warning saying that "color" is required
my only suspicion is that maybe I'm not supposed to set the view background as a color selector
Try this:
drawable xml code:-
transparent color use like this
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#android:color/transparent"" />
<stroke
android:width="1dp"
android:color="#color/selected" />
<corners android:radius="4dp" />
</shape>
Define #color/selected in color xml.
As Google's documentation here, you should not define the default statement in the first item. Here's the example they provide.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:color="#ffff0000"/> <!-- pressed -->
<item android:state_focused="true"
android:color="#ff0000ff"/> <!-- focused -->
<item android:color="#ff000000"/> <!-- default -->
</selector>
Try using hex color codes instead of color values.
I have about 8 themes in my app, I need to have a specific drawable background (XML shape) for the login page only, and that can be changed when I change the theme.
Here is my default theme:
<style name="DefaultTheme" parent="CommonDark">
<item name="colorPrimary">#color/whiteTrasparentTheme</item>
<item name="colorPrimaryDark">#color/whiteTrasparentTheme</item>
<item name="colorAccent">#color/whiteTrasparentTheme</item>
<item name="buttonStyle">#style/BlackButtonText</item>
<item name="timerColor">#color/yellowTheme</item>
<item name="timerTextColor">#color/black</item>
<item name="iconTinting">#color/yellowThemeIcon</item>
<item name="iconBG">#color/yellowThemeSecondary</item>
</style>
Any help is appreciated.
Screenshots
This is what I want:
https://imgur.com/a/Y3nf2
This is what I have on all my themes
https://imgur.com/a/wD5Gd
for that you have to create a my_background_login.xml in drawable package :
in this xml you have to put this code :
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="90"
android:centerColor="#555994"
android:endColor="#b5b6d2"
android:startColor="#555994"
android:type="linear" />
<corners
android:radius="0dp"/>
</shape>
you have specify your start color , center color and end color in xml..
then set this drawable as background in your main parent layout, so whenever you want to change you can directly change from this xml.
this is the proper way to get it done..
try it
Have a look at the picture
This is how Share button looks like in action bar.
Here's the code I use in menu xml file:
<item
android:id="#+id/menu_item_share"
android:showAsAction="ifRoom"
android:title="Share"
android:actionProviderClass=
"android.widget.ShareActionProvider" />
Is it possible to remove that border or change its color?
Here is a more complet message :
In your style, add
<style name="_MidipileTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarItemBackground">#android:color/transparent</item>
</style>
drawable/action_background
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#color/background_actionBar"/>
</shape>
#color/background_actionBar is your custom background. For me, it's the same background color as actionBar background drawable.
You need to use custom background.
This might help:
https://developer.android.com/training/basics/actionbar/styling.html
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>
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..