Skip to content

Instantly share code, notes, and snippets.

@cortinico
Created August 5, 2020 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cortinico/1c0e5db962966414d444f3e790e80c3d to your computer and use it in GitHub Desktop.
Save cortinico/1c0e5db962966414d444f3e790e80c3d to your computer and use it in GitHub Desktop.
AppIntro SlideBackgroundColorHolder example
package com.github.appintro.example.ui;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import androidx.annotation.ColorInt;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import com.github.appintro.SlideBackgroundColorHolder;
import com.github.appintro.example.R;
import org.jetbrains.annotations.Nullable;
public class ColorCustomLayoutFragment extends Fragment implements SlideBackgroundColorHolder {
private static final String ARG_LAYOUT_RES_ID = "LAYOUT_RES_ID";
private static final String ARG_COLOR_INT = "COLOR_INT";
private int layoutResId = 0;
private int originalColor = 0;
private LinearLayout background = null;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
layoutResId = getArguments().getInt(ARG_LAYOUT_RES_ID);
originalColor = getArguments().getInt(ARG_COLOR_INT);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(layoutResId, container, false);
}
@Override
public void onViewCreated(@NonNull View view, @androidx.annotation.Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
background = view.findViewById(R.id.custom_slide_background);
}
static ColorCustomLayoutFragment newInstance(@LayoutRes int layoutResId, @ColorInt int originalColor) {
ColorCustomLayoutFragment newFragment = new ColorCustomLayoutFragment();
Bundle args = new Bundle();
args.putInt(ARG_LAYOUT_RES_ID, layoutResId);
args.putInt(ARG_COLOR_INT, originalColor);
newFragment.setArguments(args);
return newFragment;
}
@Override
public int getDefaultBackgroundColor() {
return originalColor;
}
@Override
public void setBackgroundColor(int backgroundColor) {
background.setBackgroundColor(backgroundColor);
}
}
package com.github.appintro.example.ui;
import android.graphics.Color;
import android.os.Bundle;
import com.github.appintro.AppIntro;
import com.github.appintro.example.R;
import org.jetbrains.annotations.Nullable;
public class SampleIntro extends AppIntro {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addSlide(ColorCustomLayoutFragment.newInstance(R.layout.slide, Color.RED));
addSlide(ColorCustomLayoutFragment.newInstance(R.layout.slide, Color.GREEN));
addSlide(ColorCustomLayoutFragment.newInstance(R.layout.slide, Color.BLUE));
setColorTransitionsEnabled(true);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/custom_slide_background"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:layout_margin="24dp"
android:textSize="40sp" />
</LinearLayout>
@cortinico
Copy link
Author

This code will produce this AppIntro:

untitled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment