I can't find anything about that online, no documentation, nothing. Maybe one of you know how to do it or have got some advice for me.
Thank you in advance.
Update on 02/18/2022: Android 13 has official support for themed icons. Just follow their steps here: https://developer.android.com/about/versions/13/features#themed-app-icons
To follow their example:
Create a monochrome version of your app icon
Add this to your ic_launcher.xml file, under the <adaptive-icon /> tagset:
<adaptive-icon>
<background android:drawable="..." />
<foreground android:drawable="..." />
<monochrome android:drawable="#drawable/myicon" />
</adaptive-icon>
Add your icon to your manifest:
<application
…
android:icon="#mipmap/ic_launcher"
…>
</application>
Note: If android:roundIcon and android:icon are both in your manifest, you must either remove the reference to android:roundIcon or supply the monochrome icon in the drawable defined by the android:roundIcon attribute.
All of that was pulled directly from the Google developer's example.
There seems to be competing answers on this, but this issue on the Material Components GitHub repository seems to offer the most insight: https://github.com/material-components/material-components-android/issues/2357
Particularly, using an adaptive icon, like this:
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt">
<background android:drawable="#color/launcher_icon_background"/>
<foreground>
<aapt:attr name="android:drawable">
<vector
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#color/launcher_icon"
android:pathData="m54,74.5l23.3,-29c-0.9,-0.7 -9.9,-8 -23.3,-8c-13.4,0 -22.4,7.3 -23.3,8l23.3,29l0,0c0,0 0,0 0,0zm7.7,-27.3c1.4,1.7 2.3,3.9 2.3,6.3l0,2l-20,0l0,-2c0,-2.4 0.9,-4.6 2.3,-6.3l-2.3,-2.3l1.4,-1.4l2.3,2.3c1.7,-1.4 3.9,-2.3 6.3,-2.3c2.4,0 4.6,0.9 6.3,2.3l2.3,-2.3l1.4,1.4l-2.3,2.3zm-9.7,4.3c0,1.1 -0.9,2 -2,2c-1.1,0 -2,-0.9 -2,-2c0,-1.1 0.9,-2 2,-2c1.1,0 2,0.9 2,2zm8,0c0,1.1 -0.9,2 -2,2c-1.1,0 -2,-0.9 -2,-2c0,-1.1 0.9,-2 2,-2c1.1,0 2,0.9 2,2z" />
</vector>
</aapt:attr>
</foreground>
</adaptive-icon>
... with colors defined in colors.xml that refer to system-defined colors that derive from the Material 3 color pallet:
<resources>
<color name="launcher_icon_background">#android:color/system_accent1_100</color>
<color name="launcher_icon">#android:color/system_neutral1_800</color>
</resources>
Note that these colors derive from the system-defined pallet, as described in Material Design 3: https://m3.material.io/libraries/mdc-android/color-theming
You will likely have to create separate resource files that target API 31+ specifically. I have not tested out these recommendations.
Related
I want to change the color of my icon according to material You, like a google app, but the color does not change in any way. All unsuccessfully
it should be like this
or it should be like this
according to the applied theme
This process does not require Jetpack Compose at all. Android 13 has official support for themed icons. Just follow their steps here: https://developer.android.com/about/versions/13/features#themed-app-icons
To follow their example:
Create a monochrome version of your app icon
Add this to your ic_launcher.xml file, under the <adaptive-icon /> tagset:
<adaptive-icon>
<background android:drawable="..." />
<foreground android:drawable="..." />
<monochrome android:drawable="#drawable/myicon" />
</adaptive-icon>
Add your icon to your manifest:
<application
…
android:icon="#mipmap/ic_launcher"
…>
</application>
Note: If android:roundIcon and android:icon are both in your manifest, you must either remove the reference to android:roundIcon or supply the monochrome icon in the drawable defined by the android:roundIcon attribute.
All of that was pulled directly from the Google developer's example.
We use one theme for our desktop web page and another for responsive/mobile version of the site. But for mobile we don't always want to show images and it would be good if we can restrict it from the template, not just hiding it with CSS (because it still loads the image, just does not show it).
For that I need to get liferay current active theme ID or name so I can add simple if statement in the template.
#if(${themename} == "desktopTheme")
<img src="foo.jpg"/>
#end
Does anyone has ideas how to get it? I searched and checked lots of liferay's forums, but didn't find anything.
Thanks!
My advice would be to not hardcode the theme's name, but use theme settings that are readily available. Just configure your theme to be "desktop" or "mobile" style and check for this property. This way you can cover many different themes without hardcoding particular ones.
Also, the various ThemeDisplay.getTheme*() methods will help you to get the required information almost anywhere you are.
Here's some untested pseudo code for your themes (I just typed it here, never compiled/deployed, you might want to add null-checks for the VM stuff)
<?xml version="1.0"?>
<!DOCTYPE look-and-feel PUBLIC "-//Liferay//DTD Look and Feel 6.0.0//EN" "http://www.liferay.com/dtd/liferay-look-and-feel_6_0_0.dtd">
<look-and-feel>
<compatibility>
<version>6.1.0+</version>
</compatibility>
<theme id="my-desktop-1" name="My First Desktop Theme">
<settings>
<setting key="mobile" value="false" />
</settings>
</theme>
</look-and-feel>
<?xml version="1.0"?>
<!DOCTYPE look-and-feel PUBLIC "-//Liferay//DTD Look and Feel 6.0.0//EN" "http://www.liferay.com/dtd/liferay-look-and-feel_6_0_0.dtd">
<look-and-feel>
<compatibility>
<version>6.1.0+</version>
</compatibility>
<theme id="my-mobile-1" name="My First Mobile Theme">
<settings>
<setting key="mobile" value="true" />
</settings>
</theme>
</look-and-feel>
And then, in VM or JSPs or other code:
#if( ! $themeDisplay.getSetting("mobile"))
## more resources, desktop only, here.
#end
#if( $themeDisplay.getSetting("mobile")
## mobile only stuff here.
#end
And finally you might also want to consider to use the Device Detection API to determine the current device's actual capabilities on a far finer granularity
Suggest you to use themeId whis is also unique. its something the following:
xxx_WAR_xxxtheme
#if($themeDisplay.getThemeId().equalsIgnoreCase("<dektop theme id>"))
### your logic here
#end
HTH
I want to make an android layout like Google Cards,i know there is an Open Source Libraries, however i want only the Layout and the gray hex background style. I could not find information about this, how i can make this possible? im Attaching new Google maps v7 Layout so you can get the idea.
bg_card.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#CCC" />
</shape>
</item>
<item android:bottom="2dp">
<shape android:shape="rectangle">
<solid android:color="#FFF" />
</shape>
</item>
</layer-list>
Or just set the background of the card to #FFF and add at the bottom:
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#CCC" />
NOTE:
For everyone who doesn't care about using a library, you should use
a CardView from the Android support library.
Sample code.
<item name="android:windowBackground">#ffe3e3e3</item>
In your style.xml should make you happy ;-)
And for the layout, copying the card background should be enough isn't it?
We can use the LayerList as above to achieve this (OR) by using the nine patch image get same effect, we need not create nine patch image separately for this puprpose android drawable have one.
if you are using eclipse: android:background="#drawable/abc_menu_dropdown_panel_holo_light"
copy paste the above line as your View backround.
or if you are using android studio copy paste the following line:
android:background="#android:drawable/dialog_holo_light_frame"
I want to change the look (Style) of various views dynamically in an
Activity. But on going through various blogs, I came to know that
android does not support dynamically setting styles for Views
programmatic / dynamic., though I am not sure.
1) Is there any other ways of implementing apart from making use THEMES or making use layout xml files having styles pre set ?
2) Is it possible to set the different styles for various views (say green colour text for TextView1 and red color text for TextView2) by making use of setTheme() for entire Activity?
Thanks
You can change the text color in your java file like this.
textview1.setTextColor(Color.GREEN);
textview2.setTextColor(Color.RED);
Use this xml file in as resource and add it in drawable folder.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="90"
android:centerColor="#f77b2d"
android:endColor="#f99f66"
android:startColor="#f66a11" />
<stroke
android:width="0.5dp"
android:color="#313437" />
<corners
android:bottomLeftRadius="4dp"
android:bottomRightRadius="4dp"
android:topLeftRadius="4dp"
android:topRightRadius="4dp" />
</shape>
In Sharepoint 2007, I have created a layout. As you know when the user creates a page he chooses a layout from a listbox.
When you select a different element in the listbox, there is a preview image that changes on the left.
I thought this was controlled by the node PublishingPreviewImage in the xml of the layout. I have verified that the image exists in that place.
It is not working.
The code I use is:
<File Path="TituloTextoCtrl.aspx" Url="TituloTextoCtrl.aspx" Type="GhostableInLibrary" IgnoreIfAlreadyExists ="TRUE">
<Property Name="PublishingPreviewImage" Value="~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/titulotextoctrl.png, ~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/titulotextoctrl.png" />
<Property Name="MasterPageDescription" Value="Plantilla Titulo+Texto+Control" />
<Property Name="ContentType" Value="Titulo+Texto+Control" />
<Property Name="PublishingAssociatedContentType" Value=";#Vialibre_ContentTypeGeneral;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39005215cca003b74e479baa123eb1dc5702;#" />
</File>
You also need XML to provision the image:
<Module Name="MyPreviewImages" Url="_catalogs/masterpage" IncludeFolders="??-??" Path="" RootWebOnly="TRUE">
<File Url="titulotextoctrl.png" Name="Preview Images/titulotextoctrl.png" Type="GhostableInLibrary">
</File>
</Module>
first of all upload yor layout page image in site collection document library or picture libary. Then Go to site actions--> site settings-->Galleries-->master pages and pagelayouts-->. In pagelayouts you can see your new layoutpage.
choose edit properties of your layoutpage there you can see the properties of that layout page. There is one column called preview image, give the url of image there that you already uploaed in the docu libary. click on Ok, now you have got preview image of your layout page.
Thx to Rich Bennema and Hojo for answering, there are right, but at the same time, my problem is that this layouts were deployed, and when I deploy again changing the PublishingPreviewImage, the layout is not updating. So my problem was a problem of controlling events so that everytime that I deploy the layouts are recreated in case there is changes.
This I know because it has worked for new layouts.
So for those who try this. Use the code I have provided with the one of Rich Bennema to upload the image.