Menus

Tuesday, 26 February 2019

Control Statements in Android



Switch Statement


HOW TO USE SWITCH STATEMENT IN ANDROID/JAVA?


Switch case statements are a substitute for long if statements that compare a variable to several integral values
  • The switch statement is a multiway branch statement. It provides an easy way to dispatch execution to different parts of code based on the value of the expression.
  • Switch is a control statement that allows a value to change control of execution.

SYNTAX

switch(index){
    case 0:
        //Do this and this        break;
    case 1:
        //Do this and this        break;
    case 2:
        //Do this and this:        break;
    default: //For all other cases, do this        break;
}






Wednesday, 20 February 2019

How To Make Splash Screen in Android Studio



How to make Splash Screen in your android project.



Steps

Create new project to give application name as SplashScreen


Keeping minimum SDK 


Add on Activity and then finish to open new project.


Then add to EmptyActivity activity in your project.

Select EmptyActivity and give name SplashScreen




For display image copy to drawable folder.

Add to image view in activity_splash.xml file

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context="com.example.root.splashscreen.SplashActivity">

    <ImageView        
          android:layout_width="match_parent"        
          android:layout_height="match_parent"        
          android:src="@drawable/logo"        />

</RelativeLayout>


Then change theme to select NoTitlebar.


Then go to our main job as three minutes display  splash screen.

Open SplashActivity.java to add this codes

package com.example.root.splashscreen;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class SplashActivity extends AppCompatActivity {

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        Thread myThread = new Thread(){
            @Override
            public void run() {
                try {
                    sleep(3000);
                    Intent intent = new Intent(getApplicationContext(),MainActivity.class);
                    startActivity(intent);
                    finish();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        myThread.start();


        
    }
}


Then set Splash Screen to start activity.


Go to open manifest file

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.root.splashscreen">

    <application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:supportsRtl="true"        android:theme="@style/AppTheme">

        <activity android:name=".SplashActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name=".MainActivity"></activity>
    </application>

</manifest>



Code that hides title bar of activity

  1. requestWindowFeature(Window.FEATURE_NO_TITLE);//will hide the title   
  2. getSupportActionBar().hide(); //hide the title bar  

The setFlags() method of Window class is used to display content in full screen mode. You need to pass theWindowManager.LayoutParams.FLAG_FULLSCREEN constant in the setFlags method.







Sunday, 17 February 2019

Show/hide 'div' using JavaScript


Toggle between hiding and showing an element with JavaScript.


Add Html

<span class="label label-success" onclick="showDivtodo();">Show/Hide ToDo</span>
or using button
<button onclick="showDivtodo()">Show/Hide ToDo</button>     
<div  id="todo" style="display:none;">Show/Hide this text</div>
//Your code here..
</div>

Add JavaScript

function showDivtodo(){
      var x = document.getElementById("todo");
      if (x.style.display === "none") {
        x.style.display = "block";
      } else {
        x.style.display = "none";
      }        
    }


JavaScript Toggle (Hide/Show) an Element



Monday, 11 February 2019

Yii2 Create span tag in DetailView widget



The span tag is like the div tag. It has no meaning at all and is mostly used for styling by using an id or class


Code Here

[
'attribute' => 'is_status',
        'format' => 'raw',
'value' => (($model->is_status == '1') ? '<span class="label label-success">Active</span>' :      '<span class="label label-danger">Deactive</span>' ),
],


Create url in DetailView widget

           

 [
             'attribute' => 'notice_file_path',
'format' => 'raw',
'value' =>  (!empty($model->notice_file_path) ? Html::a($model->notice_file_path, ['notice-file', 'nid' => $model->notice_id], $htmlOptions=["target"=>"_blank", 'data' => ['method' => 'post',]]) : " - ")
    ],