Android:inputType не работает после добавления каллиграфии
После добавления каллиграфии к нанесенному шрифту пароль становится размытым и не может быть просмотрен. Я применил android:fontFamily="sans-serif"
но все равно все так же. Каллиграфия, которую я использую этоimplementation uk.co.chrisjenx:calligraphy:2.3.0
в то время как мой sdkVersion
21, библиотека com.android.support:appcompat-v7:27.1.1
signin.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_borenos"
tools:context="com.example.liew.idelivery.SignIn">
<LinearLayout
android:orientation="vertical"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.rengwuxian.materialedittext.MaterialEditText
android:id="@+id/edtPhone"
android:hint="Phone Number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="@android:color/white"
android:text="0128688032"
android:textColor="@android:color/white"
android:textSize="34sp"
android:inputType="phone"
app:met_baseColor="@android:color/white"
app:met_floatingLabel="highlight"
app:met_maxCharacters="12"
app:met_primaryColor="@android:color/white"
app:met_singleLineEllipsis="true"
/>
<com.rengwuxian.materialedittext.MaterialEditText
android:id="@+id/edtPassword"
android:hint="Password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="@android:color/white"
android:text="chau95"
android:fontFamily="sans-serif"
android:textColor="@android:color/white"
android:textSize="34sp"
android:inputType="textPassword"
app:met_baseColor="@android:color/white"
app:met_floatingLabel="highlight"
app:met_maxCharacters="12"
app:met_primaryColor="@android:color/white"
app:passwordToggleEnabled="true"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<com.rey.material.widget.CheckBox
android:id="@+id/ckbRemember"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Remember me"
android:textColor="@android:color/white"
app:cbd_strokeColor="@android:color/white"
app:cbd_tickColor="@android:color/black"
style="@style/Material.Drawable.CheckBox"
android:gravity="center_vertical"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@android:color/white"
android:id="@+id/txtForgotPwd"
android:text="@string/forgot_pwd"/>
</LinearLayout>
</LinearLayout>
<info.hoang8f.widget.FButton
android:id="@+id/btnSignIn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_alignParentBottom="true"
android:text="Sign In"
android:textColor="@android:color/white"
app:fButtonColor="@color/btnSignUp"
app:cornerRadius="4dp"
app:shadowColor="@android:color/black"
app:shadowEnabled="true"
app:shadowHeight="5dp" />
</RelativeLayout>
SignIn.java
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.rengwuxian.materialedittext.MaterialEditText;
import com.rey.material.widget.CheckBox;
import io.paperdb.Paper;
import uk.co.chrisjenx.calligraphy.CalligraphyConfig;
import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper;
public class SignIn extends AppCompatActivity {
EditText edtPhone,edtPassword;
Button btnSignIn;
CheckBox ckbRemember;
TextView txtForgotPwd;
FirebaseDatabase database;
DatabaseReference table_user;
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//add calligraphy
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("fonts/restaurant_font.otf")
.setFontAttrId(R.attr.fontPath)
.build());
setContentView(R.layout.activity_sign_in);
edtPhone = (MaterialEditText)findViewById(R.id.edtPhone);
edtPassword = (MaterialEditText)findViewById(R.id.edtPassword);
btnSignIn = (Button)findViewById(R.id.btnSignIn);
ckbRemember = (CheckBox)findViewById(R.id.ckbRemember);
txtForgotPwd = (TextView)findViewById(R.id.txtForgotPwd);
//Init paper
Paper.init(this);
//Init firebase
database =FirebaseDatabase.getInstance();
table_user = database.getReference("User");
txtForgotPwd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showForgotPwdDialog();
}
});
btnSignIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (Common.isConnectedToInternet(getBaseContext())) {
//save user & password
if(ckbRemember.isChecked()){
Paper.book().write(Common.USER_KEY, edtPhone.getText().toString());
Paper.book().write(Common.PWD_KEY, edtPassword.getText().toString());
}
final ProgressDialog mDialog = new ProgressDialog(SignIn.this);
mDialog.setMessage("Please waiting...");
mDialog.show();
table_user.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//check if user not exist in database
if (dataSnapshot.child(edtPhone.getText().toString()).exists()) {
//Get user information
mDialog.dismiss();
User user = dataSnapshot.child(edtPhone.getText().toString()).getValue(User.class);
// set phone
user.setPhone(edtPhone.getText().toString());
if (user.getpassword().equals(edtPassword.getText().toString())) {
Intent homeIntent = new Intent(SignIn.this, Home.class);
Common.currentUser = user;
startActivity(homeIntent);
finish();
table_user.removeEventListener(this);
} else {
Toast.makeText(SignIn.this, "Wrong Password!", Toast.LENGTH_SHORT).show();
}
} else {
mDialog.dismiss();
Toast.makeText(SignIn.this, "User not exist!", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
else{
Toast.makeText(SignIn.this, "Please check your internet connection!", Toast.LENGTH_SHORT).show();
return;
}
}
});
}
private void showForgotPwdDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Forgot Password");
builder.setMessage("Enter your secure code");
LayoutInflater inflater = this.getLayoutInflater();
View forgot_view = inflater.inflate(R.layout.forgot_password_layout, null);
builder.setView(forgot_view);
builder.setIcon(R.drawable.ic_security_black_24dp);
final MaterialEditText edtPhone = (MaterialEditText)forgot_view.findViewById(R.id.edtPhone);
final MaterialEditText edtSecureCode = (MaterialEditText)forgot_view.findViewById(R.id.edtSecureCode);
builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//check if user still available
table_user.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
User user = dataSnapshot.child(edtPhone.getText().toString())
.getValue(User.class);
if (user.getSecureCode().equals(edtSecureCode.getText().toString()))
Toast.makeText(SignIn.this, "Your password: "
+user.getpassword(), Toast.LENGTH_LONG).show();
else
Toast.makeText(SignIn.this, "Wrong secure code!", Toast.LENGTH_SHORT).show();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
});
builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.show();
}
}
1 ответ
Решение
EditTextPassword.setInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_VARIATION_PASSWORD);