Add Prefrences Screen to an Activity with a customized window title

自古美人都是妖i 提交于 2019-12-12 01:03:50

问题


I know its possible to add a button to a prefernces Screeen activtiy. I read this question How to add a button to PreferenceScreen and it works perfect. But if I want to add my custom title my application just crashes. The customtitle works perfect in its own activity and the preference screen with button works also perfect in its own activity. So my problem is only based on bringing these two functions together.

heres my code in of the java file

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();

       }
      }

this is my 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">
<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>

and heres my prefs

 <?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>

thanks guys


回答1:


still no answer?! probably u solved it already but maybe somebody else will find some of this links useful:

  • Custom title on preference screen (solved)
  • decorating preference screen article
  • How to change background color of preference

cheers



来源:https://stackoverflow.com/questions/7784756/add-prefrences-screen-to-an-activity-with-a-customized-window-title

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!