Skip to content

Instantly share code, notes, and snippets.

Manually Inflate View attachToRoot confusion

SOURCE

TLDR:

By passing in false, we say that we do not want to attach our View to the root ViewGroup just yet. We are saying that it will happen at some other point in time. In this example, the other point in time is simply the addView() method used immediately below inflation.

Also we need to pass in the parent ViewGroup if we want the child xml width and height to be honored. Visit Source for further explanation.

Question: Is it possible to create an Android shape object with stroke on only certain sides?

SOURCE

Answer:

Use the inset tag and give a negative value for the side border you want to remove.

Question: How to create a ViewPager that can see a part of next and previous item (like a Carousel)

SOURCE, more complex method SOURCE, SOURCE, SOURCE

Answer:

To show preview of left and right pages set the following two values

viewpager.setClipToPadding(false);

QUESTION: How to change Tab layout title to bold on selected?

ANSWER:

xml

<com.google.android.material.tabs.TabLayout
        android:id="@+id/fr_tab_layout"
        android:layout_width="0dp"

Android Paging Library Tutorial

SOURCE, SOURCE, SOURCE

AllClinicalNoteFragment

class AllClinicalNoteFragment : BaseLifeCycleFragment<BaseViewModel>() {
    override val viewModelClass: Class<BaseViewModel>
        get() = BaseViewModel::class.java

Listen for key Done, Search on EditText

SOURCE

Listen for Done, Search keypress on EditText (work for all device):

<EditText
  ...
  android:imeOptions="actionSearch"

Angular - Style Binding & NgStyle

SOURCE, SOURCE

Single Style Value Binding:

<p [style.background-color]="'darkorchid'">
  Quite something!
</p>

Reference duplicated View's IDs in with Kotlin synthetic

SOURCE, EXTRA

Instead of importing

kotlinx.android.synthetic.main.layout.day_row.*

AppCompatButton with Ripple effect and Lift on Touch

SOURCE

Quick answer, you can probably get most of this done by using Material Button but if you can change your app theme or it doesn't work use AppCompatButton.

<androidx.appcompat.widget.AppCompatButton
        style="@style/ButtonTextStyle.booking"
        android:text="Book Home Visit"/>

Angular animation style's attributes

SOURCE

Use camel case for CSS attribute Angular animation style:

animations: [
  trigger('openClose', [
 // ...