我的问题是我的文本视图周围没有边框。我想模拟一个基本的短信应用程序。另外,我将如何添加允许您滑动或按下它们的选项卡?先感谢您!
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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:text=""
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
/>
<EditText android:id="@+id/edit_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/edit_message"
android:layout_gravity="bottom"
/>
<Button
android:id="@+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="sendMessage"
android:text="@string/button_send"
android:layout_gravity="bottom"/>
</LinearLayou
爪哇:
import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void sendMessage(View v){
EditText editMessage=(EditText)findViewById(R.id.edit_message);
TextView textView = (TextView) findViewById(R.id.textView1);
//get text from edittext and convert it to string
String messageString=editMessage.getText().toString();
//set string from edittext to textview
textView.append(messageString+"\n");
//clear edittext after sending text to message
editMessage.setText("");
}
}