How to inherit the color of the Material You icon? Without Jetpack compose - android-layout

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.

Related

How to implement themed icons by Material You in my Android App?

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.

Single xml for multiple buttons with similar style

I want to make 3 similar buttons, the difference between them is that they are different colors. I had found out earlier that the way to give the buttons rounded corners is through creating an xml file for it, but in that case I had added the color for the button into the xml file. In this case I don't want to do that, since then I would have to make 3 virtually identical xml files to change the color for each button. Is there a way to split the code to have all three buttons reference a single xml for the button style, and have a separate line of code to just modify the color?
Within the values folder of your project, create a styles.xml file (if it doesn't already exist). Then, add code similar to below to set the common features that you want each button to have:
<!-- Style for a button -->
<style name="buttonStyle">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:fontFamily">sans-serif</item>
<item name="android:textAllCaps">false</item>
</style>
Then, in your layout file, reference this style that you just created in all three of your buttons similar to the following:
<Button
android:id="#+id/restore_button"
style="#style/buttonStyle"
android:layout_width="200dp"
android:textSize="18sp"
android:layout_height="wrap_content"
android:text="#string/restore_button_text" />
Then, change the color of each button individually with the following code in each button layout:
android:background="#android:color/white"
Finally, if you want to also create a button with rounded corners, reference this StackOverflow post for directions:
How to make the corners of a button round?
You will need to create a custom layout and reference it within each button as a Drawable.

How to get active theme name in velocity template in Liferay

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

Dynamically setting Styles for View : Android

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 I need to include a preview image for the screen of selecting layout for a new page

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.

Resources