Warning : Use SwitchCompat from AppCompat or SwitchMaterial from Material library

What is the difference between these 2 objects (SwitchCompat and SwitchMaterial)? I have tried them and visually they are identical.

By the way, why did they remove the Switch class? Do you know which UI element is supposed to replace it in the future?


The SwitchMaterial:

  • is provided by the Material Components Library
  • extends the SwitchCompat
  • uses Widget.MaterialComponents.CompoundButton.Switch as default style, using the colors defined in the Theme.MaterialComponents (like colorSecondary, colorSurface and colorOnSurface) and applying the Elevation Overlays in dark mode.

The SwitchCompat:

By the way, why did they remove the Switch class?

The Switch class is not removed. It is provided by the android framework like other widgets as Button,TextView.. and the appcompat and material components libraries provide an updated version of them (like AppCompatButton, MaterialButton…).

There is a different with these widgets.
Using an AppCompat theme there is the AppCompatViewInflater that automatically replaces all usages of core Android widgets inflated from layout files by the AppCompat extensions of those widgets (for example a Button is replaced by AppCompatButton).
Using the Theme.MaterialComponents there is the MaterialComponentsViewInflater that replaces some framework widgets with Material Components ones at inflation time, provided a Material Components theme is in use (for example a Button is replaced by MaterialButton).

It is NOT true for the SwitchMaterial and the SwitchCompat.The reason for that is due to the AppCompat SwitchCompat not actually extending from the framework Switch class.


Hilt Fragments must be attached to an @AndroidEntryPoint Activity. Found: class$EmptyFragmentActivity

I got following error when i run my unit test code.

Caused by: java.lang.IllegalStateException: Hilt Fragments must be attached to an @AndroidEntryPoint Activity. Found: class$EmptyFragmentActivity
at dagger.hilt.internal.Preconditions.checkState(
at com.zhixin.wedeep.homepage.ui.Hilt_HomePage.generatedComponent(
at com.zhixin.wedeep.homepage.ui.Hilt_HomePage.inject(
at com.zhixin.wedeep.homepage.ui.Hilt_HomePage.initializeComponentContext(
at com.zhixin.wedeep.homepage.ui.Hilt_HomePage.onAttach(
at com.zhixin.wedeep.homepage.ui.Hilt_HomePage.onAttach(
at com.zhixin.wedeep.homepage.ui.HomePage.onAttach(HomePage.kt:281)

This is my test code.

class TestHomePageFragment {

    private val c = Composition("cyrus", "background", "description", "downloadUrl", "1000", "url", "1", true, "100", 100, "100", "test", "title", "1", "100", "cover", ArrayList(), "ONCE", null)

    lateinit var cpd: CompositionDao

    var hiltRule = HiltAndroidRule(this)

    fun init() {


        cpd.createBrowseRecord(BrowseRecord(, System.currentTimeMillis()))
        val s = launchFragment<HomePage>()
        s.onFragment {
    /*    dataBindingIdlingResourceRul = DataBindingIdlingResourceRule(s)


    fun testDataInitial() {


    fun finish(){



Any idea for this question?


As stated on Hilt guide, “Testing” section:

Warning: Hilt does not currently support FragmentScenario because there is no way to specify an activity class, and Hilt requires a Hilt fragment to be contained in a Hilt activity. One workaround for this is to launch a Hilt activity and then attach your fragment.

The error is happening since hilt-managed fragment should be attached to a hilt-managed Activity as well, in short, both should be annotated with @AndroidEntryPoint. Because FragmentScenario uses an EmptyFragmentActivity to hold the underlying fragment being tested, currently there’s no way to integrate Hilt with FragmentScenario. An workaround is to launch an activity and then attach the fragment to it.


Gradient color using MaterialButton and shapeAppearance

I want to make a Button like this one : enter image description here

I try it using style with shapeAppearance :

<style name="ShapeAppearance.Button" parent="ShapeAppearance.MaterialComponents">
    <item name="cornerFamily">rounded</item>
    <item name="cornerSizeTopLeft">@dimen/button_corner_radius</item>
    <item name="cornerSizeTopRight">5dp</item>
    <item name="cornerSizeBottomRight">@dimen/button_corner_radius</item>
    <item name="cornerSizeBottomLeft">5dp</item>

<dimen name="button_corner_radius">40dp</dimen>

I apply the style in my MaterialButton like this :


The result is :

enter image description here

Now, I try to put a linear gradient :

  • #DF2D48 @ 0.0
  • #D72D46 @ 0.2
  • #AF223B @ 0.5
  • #AC2139 @ 1.0

For example :

<shape xmlns:android=""
        android:angle="360" />

and I apply it using in my Shape style :

<item name="android:background">@drawable/test</item>

But the result is the same. Why ?


Gradient color using Material Button:

Gradient MaterialButton

MaterialButton : To use a custom drawable background with the MaterialButton background tint attribute should be null ref code: app:backgroundTint=”@null”



Gradient with shape: res/drawable/gradient_1.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android=""
        android:startColor="#CC225AE0" />
        <corners android:topLeftRadius="18dp"
            android:color="#007879E8" />

How can a Discord bot create a hyperlink in a Discord message in an embed or in general? [closed]

Today I did a lot of research on hyperlinks and how to use them. But everything I found didn’t work as they were probably outdated…

How can my Discord.js bot send a message with a hyperlink? I know I can use .setTitle("Titel") and .setURL("https://...") to make a link in the embed title, but how can I use these hyperlinks elsewhere in the embed like in a field?

Also, it is possible to create a hyperlink just in a guild channel as a normal user?

Can someone help me in general with hyperlinks, or provide useful documentation which is not outdated?


Jakye is right. Only bots can achieve this (but not in field titles, beware). Just do [link text here](url here).

"Track cases globally, or in a country, by supplying 2-letter [country codes]("

This embed description results in:

this embed description

this in the embed. Clicking on it directs you to Using .addField():

yourEmbed.addField("Title here, no hyperlinks allowed", "Main text here, so you can put a hyperlink here [like so.](");

If you want a bot’s message to just be a hyperlink, you need to make an embed, and only set the description, hyperlinking as shown above. (you can set the embed color if you want too of course)


What is the difference between Clock.systemUTC() and Clock.systemDefaultZone()?

I’m looking at the Clock class from java so that I can inject it as a dependency for better testability. But I don’t understand the difference between the two methods systemUTC and systemDefaultZone. The seems to be internally using systemUTC clock whereas uses the systemDefaultZone clock. I already read the javadoc but it wasn’t very clear to me.

I have code that use and and would like to understand the difference between the two clocks with some examples where using each the clocks wrongly can lead to a problem.


In terms of the instant method of the two clocks returned by Clock.systemUTC and Clock.systemDefaultZone, they will do the same thing. Both of their documentation says that the clocks are “based on the best available system clock”. So creating Instants using the clocks will always give you the same instant.

The difference in behaviour comes when you try to create a date or time. systemUTC does this:

Conversion from instant to date or time uses the UTC time-zone.

Whereas systemDefaultZone does this:

converting to date and time using the default time-zone.

So although both will return the same instant if you ask them what the current instant is, they will not necessarily return the same LocalDateTime, or LocalDate, or ZonedDateTime. For example, suppose my system timezone is Asia/Shanghai, which is at an offset of UTC+8 all year round. And it is now 5 am on 2020-07-29 in Shanghai. If I do, it will tell me 2020-07-28, because it’s still the 28th in the UTC timezone. If I do, however, it will tell me 2020-07-29, because it is 2020-07-29 in Shanghai (which is the system timezone).

Now you should see why the parameterless now of date/time related classes use systemDefaultZone. It would be weird if I did in Shanghai and saw a time that’s 8 hours earlier!

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..