PreferenceFragment background color

前端 未结 3 1899
遥遥无期
遥遥无期 2021-01-01 11:11

I am using a PreferenceFragment (without a ListView), but am unable to set the background color, and it seems to be transparent.

How can I

相关标签:
3条回答
  • 2021-01-01 11:31

    try this.

      @Override
      public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
            super.onViewCreated(view, savedInstanceState);
            getListView().setBackgroundColor(Color.BLACK);
      }
    
    0 讨论(0)
  • 2021-01-01 11:34

    Also you can do something like changing the view's background in the onViewCreated() method.

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        view.setBackgroundColor(getResources().getColor(R.color.YOUR_COLOR));
    }
    
    0 讨论(0)
  • 2021-01-01 11:49

    This question was also answered here

    Adding the following code to your PreferenceFragment will let you add a background color, image, etc.

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        view.setBackgroundColor(getResources().getColor(android.R.color.your_color));
    
        return view;
    }
    
    0 讨论(0)
提交回复
热议问题