0

我知道可以将按钮添加到preferishs Screeen activtiy中。我读过这个问题 How to add a button to PreferenceScreen 它的工作原理非常完美。 但是,如果我想添加我的自定义标题,我的应用程序就会崩溃。 自定义标题在其自己的活动中非常完美,并且带有按钮作品的首选项屏幕也完美适用于自己的活动。所以我的问题只是基于将这两个功能结合在一起。将Prefrences屏幕添加到具有自定义窗口标题的活动

我的继承人在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> 

谢谢你们

回答

相关问题