activity_main.xml
<?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:id="@+id/rl" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="16dp" tools:context=".MainActivity" android:background="#cbd1d1" > <TextView android:id="@+id/tv" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="30dp" android:layout_margin="5dp" android:padding="5dp" android:fontFamily="sans-serif-condensed" android:textColor="@android:color/black" /> </RelativeLayout>
MainActivity.java
package com.cfsuman.me.androidcodesnippets; import android.app.Activity; import android.content.Context; import android.os.Build; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.RelativeLayout; import android.widget.TextView; public class MainActivity extends AppCompatActivity { private Context mContext; private Activity mActivity; private RelativeLayout mRelativeLayout; private TextView mTextView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Get the application context mContext = getApplicationContext(); // Get the activity mActivity = MainActivity.this; // Get the widgets reference from XML layout mRelativeLayout = (RelativeLayout) findViewById(R.id.rl); mTextView = (TextView) findViewById(R.id.tv); // Initialize few variables to hold android os build version berita /* CODENAME The current development codename, or the string "REL" if this is a release build. */ String codeName = Build.VERSION.CODENAME; /* INCREMENTAL The internal value used by the underlying source control to represent this build. */ String incremental = Build.VERSION.INCREMENTAL; /* RELEASE The user-visible version string. */ String release = Build.VERSION.RELEASE; /* SDK_INT The user-visible SDK version of the framework; its possible values are defined in Build.VERSION_CODES. */ int sdkInt = Build.VERSION.SDK_INT; // Display the build information to TextView mTextView.setText("android.os.Build.VERSION Information...."); mTextView.setText(mTextView.getText() + "\nCODE NAME : " + codeName); mTextView.setText(mTextView.getText() + "\nINCREMENTAL : " + incremental); mTextView.setText(mTextView.getText() + "\nRELEASE : " + release); mTextView.setText(mTextView.getText() + "\nSDK INT : " + sdkInt); } }
Komentar
Posting Komentar