Skip to content

Instantly share code, notes, and snippets.

View dynoChris's full-sized avatar
🎯
Focusing

dyno_chris dynoChris

🎯
Focusing
View GitHub Profile
@dynoChris
dynoChris / MainActivity.java
Last active December 9, 2018 01:08
How to hide status bar in Android
//source: https://developer.android.com/training/system-ui/status
View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
@dynoChris
dynoChris / activity_main.xml
Last active October 7, 2018 17:10
How to change text appearance of text in Android
//link: http://developer.alexanderklimov.ru/android/theory/scales.php
//
//examples
//**********************
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
@dynoChris
dynoChris / round_button.xml
Last active June 20, 2021 20:55
How to make ripple effect to the button in android on the example of a round button
//link: https://stackoverflow.com/questions/9884202/custom-circle-button
//place to the drawable folder as ripple_effect.xml
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@android:color/holo_green_light">
<item>
<shape android:shape="rectangle">
<corners android:radius="200dp"/>
@dynoChris
dynoChris / Sending simple text
Created November 30, 2018 06:57
How to send simple text with Intent in Android
String text = "some text";
shareText(text);
private void shareText(String text) {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(shareIntent, "Share text"));
}
@dynoChris
dynoChris / StatusBarUtils.java
Created December 9, 2018 01:03
How to make transparent status bar in Android
public class StatusBarUtils {
public static void makeTransparentStatusBar(Activity activity) {
if (Build.VERSION.SDK_INT >= 19 && Build.VERSION.SDK_INT < 21) {
setWindowFlag(activity, true);
}
if (Build.VERSION.SDK_INT >= 19) {
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
//make fully Android Transparent Status bar
@dynoChris
dynoChris / MultiSelectListPreferenceFix.java
Last active December 9, 2018 20:09
How to fix bug with MultiSelectListPreference in android
//Many thanks to this author https://github.com/chroaster/MSLPBug
//I use adnroidx, but you can use any support libraries
//Notice, it issue use deprecated methods, but I don't see problem with performence of app.
//**********************
package com.example.mslpfixdemo;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.Context;
@dynoChris
dynoChris / navigation_menu.xml
Created January 16, 2019 08:36
How to highlight selected item in NavigationView
<!--just add one parameter — checkable="true"-->
<!--'checked' highlight some item in default-->
<item
android:id="@+id/some_item"
android:checkable="true"
android:checked="true"
android:icon="@drawable/ic_icon"
android:title="@string/string" />
@dynoChris
dynoChris / Class1.java
Created January 18, 2019 17:55
How to show custom dialog in Android
Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(false);
dialog.setContentView(R.layout.progress_layout);
dialog.show();
@dynoChris
dynoChris / Utils.java
Last active January 20, 2019 15:05
How to set margin programmatically in Android?
public static void setMargins (View view, int left, int top, int right, int bottom) {
if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
p.setMargins(left, top, right, bottom);
view.requestLayout();
}
}
//How to call it — Utils.setMargin(imageView, 0, 20, 0, 0);
@dynoChris
dynoChris / SomeClass.java
Created January 21, 2019 00:54
Set scroll flags to Collapsing Toolbar
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) collapsToolbar.getLayoutParams();
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED);
collapsToolbar.setLayoutParams(params);
//clear scroll flags — params.setScrollFlags(0);