Im rất mới để phát triển android này. Tôi chỉ mới bắt đầu tạo ứng dụng chào thế giới.Làm thế nào để thiết lập hình nền trong android
Tôi đã cố gắng đặt hình nền và hình ảnh hoạt động tốt. Khi tôi cố gắng thêm văn bản trên hình ảnh không hoạt động.
Tôi đã thử theo cách dưới đây. Bất kỳ ai cũng có thể giúp tôi khi có lỗi xảy ra.
trong
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/andriod"
android:layout_gravity="center_vertical"
android:gravity="center_vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>
HelloActivity.java
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
//import android.widget.ImageView;
public class HelloActivity extends Activity {
// /** Called when the activity is first created. */
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
// }
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("This is the first andorid app");
setContentView(R.layout.main);
}
}
Khi chạy nó là hiển thị hình nền nhưng "Đây là ứng dụng đầu tiên andorid" không hiển thị.
Hy vọng giúp đỡ của bạn
@ishhhh: Bạn đang đặt văn bản trong TV TextView, nhưng không thêm TV này vào bố cục. – Mudassir