Android中带编辑文本和按钮的Backgorund图像
我是一个非常新手的android开发者,正在努力了解这些东西。我有一个图像,它有一个Android中带编辑文本和按钮的Backgorund图像,android,Android,我是一个非常新手的android开发者,正在努力了解这些东西。我有一个图像,它有一个EditText字段和一些按钮。所以我们可以说我们有EditText和按钮作为用户输入控件。现在我想用这个图像作为背景图像 <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent"
EditText
字段和一些按钮。所以我们可以说我们有EditText和按钮作为用户输入控件。现在我想用这个图像作为背景图像
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/bg">
</LinearLayout>
因此,我这里的问题是如何从EditText
字段中获取输入值,以及如何设置按钮的事件
请帮帮我。试试这个方法:
xml文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:background="@drawable/bg"
android:gravity="center"
android:orientation="vertical" >
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher"
android:ems="10" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher"
android:ems="10" />
<Button
android:id="@+id/the_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher"
android:text="Set" />
</LinearLayout>
在您的应用程序中,创建:
edit1 = (EditText)findViewById(R.id.editText1);
edit2 = (EditText)findViewById(R.id.editText2);
bt = (button)findViewById(R.id.button1);
bt.setOnclickListener(onCLi);
然后在onCreate之外声明您的onClickListener:
private View.OnClickListener onCli = new View.OnClickListener() {
@Override
public void onClick(View v) {
String editvalue1 = edit1.getText().toString();
String editvalue2 = edit2.getText().toString();
System.out.prinltn("Value1: "+editvalue1 +"and value2: "+editvalue2);
}
};
完整的Java实现:
public class YourClass extends Activity {
EditText edit1, edit2;
Button bt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_layout);
edit1 = (EditText)findViewById(R.id.editText1);
edit2 = (EditText)findViewById(R.id.editText2);
bt = (button)findViewById(R.id.button1);
bt.setOnclickListener(onCLi);
}
private View.OnClickListener onCli = new View.OnClickListener() {
@Override
public void onClick(View v) {
String editvalue1 = edit1.getText().toString();
String editvalue2 = edit2.getText().toString();
System.out.prinltn("Value1: "+editvalue1 +"and value2: "+editvalue2);
}
};
}
你必须将所有内容分开,背景应该是简单的。为什么你不能从
EditText
字段中获取输入值,你面临的问题是什么?@Sree我如何才能从背景图像中获取输入值?@Nun'eChai请你解释一下,我是一个非常新手..向我们展示你的尝试,你最好在安卓系统中学习一些基本的教程,这些教程有助于解决你的问题我得到了你的答案,并且在我尝试学习安卓系统时没有什么疑问,我会说这是我的第一堂课。我想知道如何设置编辑文本的样式,以及如何在按钮上添加图像,因为我在几乎所有的应用程序中都看到了这一点。请帮助..谢谢必须使用以下xml格式在按钮中添加背景图像:android:background=“@drawable/buttonimage”
编辑文本也可以这样做。我已经更新了上面答案中的xml,请检查它以供参考。我否决了你的问题,因为还有改进的余地,请不要接受它。
public class YourClass extends Activity {
EditText edit1, edit2;
Button bt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_layout);
edit1 = (EditText)findViewById(R.id.editText1);
edit2 = (EditText)findViewById(R.id.editText2);
bt = (button)findViewById(R.id.button1);
bt.setOnclickListener(onCLi);
}
private View.OnClickListener onCli = new View.OnClickListener() {
@Override
public void onClick(View v) {
String editvalue1 = edit1.getText().toString();
String editvalue2 = edit2.getText().toString();
System.out.prinltn("Value1: "+editvalue1 +"and value2: "+editvalue2);
}
};
}