设置活动操作栏导航单击失败,并带有嵌套首选项

时间:2019-02-03 11:55:39

标签: android android-preferences preferenceactivity

我在Settingsactivity中有以下内容

public class SettingsActivity extends AppCompatPreferenceActivity {

   @Override
   protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     ActionBar actionBar = getSupportActionBar();
     if (actionBar != null) {
        // Show the Up button in the action bar.
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
   }


    //NESTED PREFERENCE
      @TargetApi(Build.VERSION_CODES.HONEYCOMB)
   public static class GeneralPreferenceFragment extends PreferenceFragment {

     @Override
     public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == android.R.id.home) {
            startActivity(new Intent(getActivity(), SettingsActivity.class));
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

   }

}

在嵌套首选项“常规”首选项中,单击后退箭头可将其返回到settingsActivity

现在在设置活动中,我想添加一个后单击列表器以重新定向到仪表板。我添加了

public class SettingsActivity extends ...{

           @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == android.R.id.home) {
             startActivity(new Intent(this, DashboardActivity.class));
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

 }

此重新定向到dahsboard,但将嵌套的首选项片段弄乱了,因为它也重新定向到了仪表板

我如何分隔两个家庭点击事件,以便在常规首选项上单击它时会打开设置活动,而在设置活动中时应打开仪表板活动

0 个答案:

没有答案