Posts

Showing posts from May, 2022

Number with Comma (9,999)

 Number with Comma (9,999) It's very easy if you're using Sketchware Pro. Follow this: Just go to Blocks then Operator and then scroll down and choose toDecimalFormat and then type this ###,### inside the box of toDecimalFormat while the circle is the number value If you're not using Sketchware Pro. Follow this: Go to Activity and put this code textview1.setText(new DecimalFormat("###,###").format(25)); ###,### - To make the number format like 999,999,999,999 25 - Is the value

onTouchListener Hover Effect

 onTouchListener Hover Effect Hover effect when you touch the view and release it. Like when I touch it the button the button text will be "TOUCHING..." and after I release it it will be "Touched, done". Codes: button1.setOnTouchListener(new OnTouchListener() {             @Override             public boolean onTouch(View v, MotionEvent event) {                 if(event.getAction() == MotionEvent.ACTION_DOWN){      // PUT YOUR CODE HERE WHEN TOUCHING, ILL PUT MINE       button1.setText("TOUCHING..."); } if(event.getAction() == MotionEvent.ACTION_UP){      // PUT YOUR SECOND CODE HERE WHEN RELEASED       button1.setText("TOUCHED"); }                 return false;             }         });

Status Bar Text Visibility

 Status Bar Text Visibility The text of status bar can't see when you set your status bar color to white, so to fix it you only need this one code in your Activity. It will automatically make your status bar text visible. Codes: linear1.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);

Get X, Y Position of Layout

Get X, Y Position of Layout Detect the position of layout by following the steps. Step 1: Create two number variables, I'll name it x and y Step 2: Put this code: float x = Math.round(textview1.getX()); float y = Math.round(textview1.getY()); If you want to set the X, Y position of Layout follow this additional step. Step 3: textview1.setX((float)200)); textview1.setY((float)50));

EditText Max Characters

 EditText Max Characters Limit your EditText max characters by putting this simple code in your Activity. Codes: int maxLength = 50; InputFilter[] filters = new InputFilter[1]; filters[0] = new InputFilter.LengthFilter(maxLength); edittext1.setFilters(filters); 50 - 50 characters only edittext1 - EditText ID

TextView Marquee Effect

 TextView Marquee Effect Marquee Effect for your TextView in simple code. Codes: textview = (TextView) findViewById(R.id.textview1); textview.setText("Your Text Here"); textview.setSingleLine(true); textview.setEllipsize(TextUtils.TruncateAt.MARQUEE); textview.setSelected(true); textview1 - TextView ID

Avoid BackPressed Restart

 Avoid BackPressed Restart This simple code will save you from your app being restarted when pressed the back button. Codes: Put this code inside your OnBackPressed Activity: moveTaskToBack(true);

TextView Gradient Color

 TextView Gradient Color Put this code in your activity to change your TextView color into gradient. Codes: textview = (TextView) findViewById(R.id.textview1);         TextPaint paint = textview.getPaint();         float width = paint.measureText("Put your text here");         Shader textShader = new LinearGradient(0, 0, width, textview.getTextSize(),                 new int[]{                         Color.parseColor("#C97C3C"),                         Color.parseColor("#EDB54E"),                         Color.parseColor("#A4B678"),                         Color.parseColor("#4788EA"),                   ...

Hide or Show Scroll Bar

 Hide or Show Scroll Bar By using this simple code, you can show or hide the scroll bar of ScrollView, ListView, RecyclerView or GridView. Codes: To hide: vscroll1.setVerticalScrollBarEnabled(false); To show: vscroll1.setVerticalScrollBarEnabled(true); vscroll1 - Scroll Layout ID (scrollview , listview, etc)

Text To Speech Voice & Accents

 Text To Speech Voice & Accents Simple code to change your text to speech voice or accent. Codes: tts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener(){ @Override public void onInit(int status){ if(status != TextToSpeech.ERROR){ tts.setLanguage(new Locale("fil-ph")); } }}); tts - Text To Speech ID fil-ph - Your Language Code (https://cloud.google.com/text-to-speech/docs/voices)

Check if Visible or GONE

 Check if Visible or GONE You can check if layout is visible, invisible or gone by using this code: Code: imageview1.getVisibility(); Example: if(imageview1.getVisibility() == View.VISIBLE){      imageview1.setVisibility(View.INVISIBLE); }

Layout Shadow

Layout Shadow You can have your linear layout a shadow by using this simple code: Code: linear1.setElevation((float)6.2); linear1 - Linear Layout ID float - To use decimal numbers 6.2 - Value

HTML to TextView

HTML to TextView You can convert an HTML code (only with text) to TextView by following the steps. Step 1: Create a string variable, I'll name it html_string Step 2: Set your string value (html_string) to the HTML codes you want to use, e.g.: <span style="color: #F44336"><b>URL</b></span>: skeshwarecodes.blogspot.com Step 3: Add this code after: textview1.setText(Html.fromHtml(html_string)); textview1.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());

Lottie Animation

 Lottie Animation You can play, set progress or pause a lottie animation. Play lottie1.playAnimation(); Set Progress lottie1.setProgress(0); Pause Animation lottie1.pauseAnimation();

Avoid App Restart

Avoid App Restart This problem happens when you click your app it will restart. To avoid this bug, all you have to do is to put this java code in your MainActivity. Code: if(!isTaskRoot()){      finish();      return; }