Add Prefrences Screen to an Activity with a customized window title
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开发者_如何学Python://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
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
精彩评论