I used Gravity.CENTER
, which centered the text in EditText and not EditText in Activity.
package com.example.wbsoftware.testetcc;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class Main2Activity extends AppCompatActivity {
private LinearLayout layout;
private EditText[] vetorEdits;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
layout = (LinearLayout) findViewById(R.id.layout);
int count = getIntent().getIntExtra("qtd", 0);
vetorEdits = new EditText[count];
for(int i=0; i<count; i++){
vetorEdits[i] = new EditText(Main2Activity.this);
vetorEdits[i].setHint("Periodo " + (i+1));
vetorEdits[i].setHintTextColor(Color.WHITE);
vetorEdits[i].setGravity(Gravity.CENTER);
vetorEdits[i].setTextColor(Color.WHITE);
layout.addView(vetorEdits[i], new ViewGroup.LayoutParams(300,150));
}
}
}