Skip to content

Instantly share code, notes, and snippets.

@geekygecko
Last active October 14, 2022 19:32
Show Gist options
  • Star 57 You must be signed in to star a gist
  • Fork 16 You must be signed in to fork a gist
  • Save geekygecko/0ea6358baed26636a08d to your computer and use it in GitHub Desktop.
Save geekygecko/0ea6358baed26636a08d to your computer and use it in GitHub Desktop.
Android Cheat Sheet

Android Cheat Sheet

Developer tips

Record a video of your app

Developer options -> Check show touches
adb shell screenrecord /sdcard/video.mp4
adb pull /sdcard/video.mp4

Logcat while two devices connected

adb devices
adb -s SA5A330471 logcat | grep --line-buffered Playback

Easily input text

adb shell input text yourusername;
adb shell input keyevent 66;
adb shell input text yourpassword;
adb shell input text "Can%swe%sstill%sbe%sfriends"

Styles

Font family

android:fontFamily="sans-serif"                 // roboto regular
android:fontFamily="sans-serif-light"           // roboto light
android:fontFamily="sans-serif-condensed"       // roboto condensed
android:fontFamily="sans-serif-condensed-light" // roboto condensed light
android:fontFamily="sans-serif-thin"            // roboto thin (android 4.2)
android:fontFamily="sans-serif-medium"          // roboto medium (android 5.0)

XML layouts

// android
xmlns:android="http://schemas.android.com/apk/res/android"
// library extension
xmlns:fab="http://schemas.android.com/apk/res-auto"
// designer tools
xmlns:tools="http://schemas.android.com/tools"

Fragments

public class LocationFragment extends Fragment {
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
  }

  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.location_fragment, container, false);
    return view;
  }

  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
  }

  public void onResume() {
    super.onResume();
  }

  public void onPause() {
    super.onPause();
  }

  public void onDestroy() {
    super.onDestroy();
  }
}

Create with parameters

public static final String EXTRA_LOCATION = "your.package.LOCATION";

public static final LocationFragment newInstance(Location location) {
  LocationFragment fragment = new LocationFragment();
  Bundle bundle = new Bundle(1);
  bundle.putSerializable(EXTRA_LOCATION, location);
  fragment.setArguments(bundle);
  return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  Location location = (Location)getArguments().getSerializable(EXTRA_LOCATION);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment