Android 개발에 새로 도입되었습니다. 텍스트 입력 필드와 버튼이있는 교육용 앱이 있습니다. 입력 된 텍스트가 단어와 일치하는 경우 button click
은 일부 텍스트를 표시하는 새 페이지 (의도?)를 만듭니다.Android 버튼 이미지를 클릭하면 배경 이미지가 사라집니다.
내가 겪고있는 문제는 버튼 클릭으로 생성 된 새 페이지에는 기본 페이지와 동일한 배경 이미지가 없다는 것입니다. 나는 이유를 모른다. 지금까지 내가 가지고있는 관련 코드 비트는 다음과 같습니다. 필요한 경우 더 게시 할 수 있습니다.
**fragment_welcome_screen.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"
android:background="@drawable/bg_pic">
<EditText android:id="@+id/edit_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/edit_message"
android:layout_weight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="sendMessage"/>
</LinearLayout>
이 부분은 잘 작동하고 bg_pic이 표시됩니다.
WelcomeScreen.java
public void sendMessage(View view) {
// Do something in response to button
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
if ((message.equals("Secret"))||(message.equals("secret"))) {
Intent intent = new Intent(this,
DisplayMessageActivity.class);
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}
나는 "비밀"에 입력되어있는 경우 버튼 만 작동합니다.
DisplayMessageActivity.java
public class DisplayMessageActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
// Get the message from the intent
Intent intent = getIntent();
//String message = intent.getStringExtra(WelcomeScreen.EXTRA_MESSAGE);
String message = "Test String";
TextView textView = new TextView(this);
textView.setTextSize(24);
textView.setText(message);
// Set the text view as the activity layout
setContentView(textView);
}
내가 아마 잘못 여기서 뭔가를하고 있어요 알고있다.
activity_display_message.xml
<RelativeLayout
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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:background="@drawable/test_pic"
tools:context="com.example.varun.myapplication.DisplayMessageActivity">
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:background="@drawable/test_pic"/>
</RelativeLayout>
나는 test_pic이 버튼을 눌렀을 때 표시되는 페이지의 배경이 될 것으로 기대합니다. 그러나 그렇지 않습니다. 배경은 흰색뿐입니다.
나는 이것이 아마도 사소한 질문이라는 것을 알고 있지만 누군가 나를 도울 수 있습니까? 나는 정말로 감사 할 것입니다.
감사합니다.
당신의 텍스트 뷰에 "android : background ="@ drawable/test_pic "도 있습니다. 따라서 액티비티 배경은 textview의 것과 같습니다. –
환영 활동에서 bg_pic을 배경으로 사용하고 DisplayMessageActivity를 test_pic을 배경으로 사용하여 배경을 동일하게 두 활동 모두에 대해 –