Я знаю, что этот вопрос задан несколько раз и с разными решениями, но я пробовал все, что мог найти здесь, и никто не работал. Как видно из названия, в Android Studio поле моего виджета EditText не показывает какой-либо текст, даже тот, который он имеет по умолчанию (например, подсказка и текст по умолчанию). Текст есть, если я распечатаю его, но не покажу. Это для простой страницы входа.Android Studio - текст EditText, как подсказка, так и обычный текст, а не отображение
Это файл XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:text="Name : "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginStart="30dp"
android:layout_marginTop="40dp"
android:id="@+id/atcoNameTag" />
<TextView
android:text="Password : "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/atcoNameTag"
android:layout_marginTop="30dp"
android:id="@+id/passTag"
android:layout_alignStart="@+id/atcoNameTag"/>
<TextView
android:text="Role : "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:id="@+id/roleNameTag"
android:layout_below="@+id/passTag"
android:layout_alignStart="@+id/atcoNameTag"/>
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:inputType="text"
android:ems="10"
android:layout_above="@+id/passTag"
android:layout_centerHorizontal="true"
android:id="@+id/insertName"
android:layout_alignTop="@+id/atcoNameTag"
android:layout_toEndOf="@+id/atcoNameTag"
android:layout_alignStart="@+id/insertPass"
android:hint="username"
android:cursorVisible="true"/>
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:layout_alignBottom="@+id/passTag"
android:layout_toEndOf="@+id/passTag"
android:id="@+id/insertPass"
android:layout_alignTop="@+id/passTag"
android:hint="password"
android:cursorVisible="true"/>
<Spinner
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="@+id/spinner"
android:layout_alignTop="@+id/roleNameTag"
android:layout_toEndOf="@+id/roleNameTag"
android:layout_alignStart="@+id/insertPass"/>
<Button
android:text="Login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/loginButton"
android:onClick="onClick"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="35dp" />
</RelativeLayout>
И это Java-файл:
package mecals.mecalsapp;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
public class LoginActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login_page);
Button nameBtn = (Button) findViewById(R.id.loginButton);
nameBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText nameEntry = (EditText) findViewById(R.id.insertName);
nameEntry.setTextColor(Color.BLACK);
String name = nameEntry.getText().toString();
//TODO username checking, username not showing , need devC Team's work
if (name.length() > 0) {
Toast toastYes = Toast.makeText(getApplicationContext(), "Hi there, " + name + "!", Toast.LENGTH_SHORT);
toastYes.show();
Intent intent = new Intent(getApplicationContext(),HomeActivity.class);
startActivity(intent);
} else {
Toast toastNo = Toast.makeText(getApplicationContext(), "Please insert name !", Toast.LENGTH_SHORT);
toastNo.show();
}
EditText passwordEntry = (EditText) findViewById(R.id.insertPass);
passwordEntry.setTextColor(Color.BLACK);
String pass = passwordEntry.getText().toString();
//TODO password checking , need devC Team's work
}
});
}
}
И эти решения я пытался, но безрезультатно:
Difference between content_main.xml and activity_main.xml?
Android edittext typed text not showing
Android EditText typed value not showing
Text not displayed in Android editText when changing android:hint to android:text
EditText in Android doesn't show text when typing while using the on-screen keyboard
Edit Text hints not appearing on later version SDK
edittext not showing the typed text in android
Короче говоря, у меня есть
-множество тыс цвет текста - черный, с именемEntry.setTextColor (Color.BLACK);
-I добавили андроида: windowSoftInputMode = "adjustPan" в проявленном
-I не использовали что-то вроде Android: гравитацию, просто андроид: макет
-The курсор установлен на видимый
-I даже проверил высоту виджета
-I проверил размер текста с андроид: Эмс быть 10
- и тип ввода установлен в текст для первого поля и textPassword для второго
Помощь!
PS: прежде чем кто спрашивает, мой Android-студия версия 2.2.3, и API я использую мин 21.
Привет, Beta_K, я имел игру с вашим кодом и можете подтвердить, снимаете ли вы следующую строку с дизайнера android: layout_above = "@ + id/passTag" покажет вам подсказку и ввод ur, которые вы вводите. Однако это испортит ваш макет – chirag90
Спасибо, это было правильно :) –
Добро пожаловать. – chirag90