Skip to content

Instantly share code, notes, and snippets.

@thaiall
Created August 10, 2017 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thaiall/e55bca08d5927c97dd2dec5367771085 to your computer and use it in GitHub Desktop.
Save thaiall/e55bca08d5927c97dd2dec5367771085 to your computer and use it in GitHub Desktop.
Android Studio : Layoutofnotification
package com.thaiall.www.layoutofnotification;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.support.v7.widget.Toolbar.LayoutParams;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private void layoutRuntime() {
LinearLayout linearLayout = new LinearLayout(this);
TextView ProgrammaticallyTextView = new TextView(this);
ProgrammaticallyTextView.setText(R.string.runtime);
ProgrammaticallyTextView.setTextSize(16);
ProgrammaticallyTextView.setPadding(30, 250, 30, 100);
linearLayout.addView(ProgrammaticallyTextView);
this.setContentView(linearLayout, new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
//http://www.android-examples.com/android-create-textview-programmatically-example/
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
//if (id == R.id.action_settings) {
// return true;
//}
//return super.onOptionsItemSelected(item);
switch (item.getItemId()) {
case R.id.content1:
findViewById(R.id.content1).setVisibility(View.VISIBLE);
findViewById(R.id.content2).setVisibility(View.GONE);
return true;
case R.id.content2:
findViewById(R.id.content1).setVisibility(View.GONE);
findViewById(R.id.content2).setVisibility(View.VISIBLE);
return true;
case R.id.layoutRuntime:
layoutRuntime();
return true;
default:
// If we got here, the user's action was not recognized.
// Invoke the superclass to handle it.
return super.onOptionsItemSelected(item);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment