我正在以编程方式在Android上创建一个按钮而不使用任何XML。我将所有填充设置为0,但它仍然显示出来。如何修复它,以便我可以将edittext刷新到左侧。
以下是代码:
公共类LoginActivity扩展了AppCompatActivity {
EditText emailEditText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
LinearLayout loginLayout = (LinearLayout) findViewById(R.id.activity_login);
setTitle("Login");
emailEditText= new EditText(this);
emailEditText.setHint(R.string.email);
GradientDrawable background = new GradientDrawable();
background.setColor(getApplicationContext().getResources().getColor(R.color.webOrange));
emailEditText.setBackground(background);
emailEditText.setId(View.generateViewId());
LinearLayout.LayoutParams emailParams= new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
150
);
emailParams.topMargin = 40;
emailEditText.setPadding(0,0,0,0);
loginLayout.addView(emailEditText, emailParams);
}
}
登录活动的XML文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_login"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@color/wildSand"
tools:context="com.zensports.zensports.LoginActivity">
</LinearLayout>
以下是模拟器上的截图:
我想删除左边距,然后将hint
文字更多地移到右边。
谢谢!