Forked from ankit-lakhanpal/MainActivity.java
Last active
September 19, 2016 09:25
-
-
Save ahmadmust8/0bd5463344d2a5e35f1883e0b1f7e158 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.lakhanpal.ankit.alison; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.Menu; | |
import android.view.MenuItem; | |
import android.widget.RelativeLayout; | |
import android.widget.Button; | |
import android.graphics.Color; | |
import android.widget.EditText; | |
import android.content.res.Resources; | |
import android.util.TypedValue; | |
import org.w3c.dom.Text; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
//converting px type to dip | |
//( Resources r=getResources(); //get information about phone ) -> we don't need this object (; | |
int px=(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,200,getResources.getDisplayMetrics()); | |
//Button | |
Button redbutton= new Button(this); | |
RelativeLayout.LayoutParams buttonDetails= new RelativeLayout.LayoutParams( | |
RelativeLayout.LayoutParams.WRAP_CONTENT, | |
RelativeLayout.LayoutParams.WRAP_CONTENT | |
); | |
buttonDetails.addRule(RelativeLayout.CENTER_HORIZONTAL); | |
buttonDetails.addRule(RelativeLayout.CENTER_VERTICAL); | |
RelativeLayout AnkitsLayout=new RelativeLayout(this); | |
redbutton.setText("login"); | |
redbutton.setBackgroundColor(Color.CYAN); | |
redbutton.setId(1); | |
//Text | |
EditText username = new EditText(this); | |
RelativeLayout.LayoutParams usernameDetails =new RelativeLayout.LayoutParams( | |
RelativeLayout.LayoutParams.WRAP_CONTENT, | |
RelativeLayout.LayoutParams.WRAP_CONTENT | |
); | |
usernameDetails.addRule(RelativeLayout.ABOVE, redbutton.getId()); | |
usernameDetails.addRule(RelativeLayout.CENTER_HORIZONTAL); | |
usernameDetails.setMargins(0, 0, 0, 50); | |
username.setWidth(px); | |
AnkitsLayout.setId(2); | |
AnkitsLayout.addView(redbutton, buttonDetails); | |
AnkitsLayout.setBackgroundColor(Color.BLUE); | |
AnkitsLayout.addView(username, usernameDetails); | |
setContentView(AnkitsLayout);//set the content after last addView method. | |
} | |
@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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment