0

設定画面のアクティビティにボタンを追加できることを知っています。この質問を読んだ PreferenceScreenにボタンを追加する方法 完璧に機能します。しかし、カスタム タイトルを追加したい場合、アプリケーションがクラッシュします。customtitle は独自のアクティビティで完璧に機能し、ボタン付きの設定画面も独自のアクティビティで完璧に機能します。したがって、私の問題は、これら 2 つの機能を組み合わせることにのみ基づいています。

Javaファイルの私のコードはここにあります

public class TestHeadlineActivity extends PreferenceActivity implements OnClickListener{
   /** Called when the activity is first created. */
Button settingsButton;
TextView tv_WindowTitleAccuracy;

    @Override
    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
       addPreferencesFromResource(R.xml.prefs);
       setContentView(R.layout.main);
       getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
       settingsButton = (Button) findViewById(R.id.Button_Settings);
       settingsButton.setText("BUTTONTEXT");
   settingsButton.setOnClickListener(this);
   tv_WindowTitleAccuracy = (TextView) findViewById(R.id.tv_WindowTitleAccuracy);
   tv_WindowTitleAccuracy.setText("TEXT");

   }

 @Override
 public void onClick(View v) {

     finish();

       }
      }

これは私のメインの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">
<ListView android:id="@android:id/list"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" android:layout_weight="10"/>
<Button android:text="This is a button on top of all preferences."
          android:layout_height="wrap_content" 
          android:layout_weight="1" android:layout_width="fill_parent"/>
</LinearLayout>

ここに私の設定があります

 <?xml version="1.0" encoding="utf-8"?>
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

 <EditTextPreference
    android:title="EditText"
    android:key="name"
    android:summary="Enter your name"
    ></EditTextPreference>

  <CheckBoxPreference 
    android:title="Music"
    android:defaultValue="true"
    android:key="checkbox"
    android:summary="for the splash screen"
     />
  </PreferenceScreen>

みんなありがとう

4

1 に答える 1

0

まだ答えがない?! おそらくあなたはすでに解決していますが、他の誰かがこのリンクのいくつかを役に立つと思うでしょう:

乾杯

于 2012-08-13T13:46:36.590 に答える