Skip to content

Instantly share code, notes, and snippets.

public class SplashView extends View {
private Bitmap bitmap;
public SplashView(Context context) {
super(context);
init();
}
private void init() {
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.logo);
// Using R.layout.activity_main from the main source set
import kotlinx.android.synthetic.main.activity_main.*
public class MyActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
textView.setText("Hello, world!") // Instead of findView(R.id.textView) as TextView
}
}
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//click handling
}
});
view.setOnClickListener({/**click handling*/})
view.setOnClickListener({//click handling})
if (s != null) ? s.length() : 0
s?.length ?: -1
fun AppCompatActivity.navigate(frag: Fragment) {
val fragmentTransaction = supportFragmentManager.beginTransaction()
fragmentTransaction.replace(content.id, frag);
fragmentTransaction.commit();
}
fun Fragment.userError(msg: String?) {
Snackbar.make(view, msg, Snackbar.LENGTH_LONG).show()
}
Layout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/processed_image_background">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/image_selector"
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:name="line"
android:pathData="M5.705,5.705 L18.295,18.295"