相关疑难解决方法(0)

在"首选项行"中添加一个按钮

我想在"设置"屏幕中显示一个按钮.这里已经提出这个确切的问题.但遗憾的是没有答案.:(

在此输入图像描述

为了达到这个目的,我创建了一个这样的自定义首选项 -

  public class CustomPreference extends Preference {

    private LinearLayout mWidgetContainer;
    private View mRowView;

    public CustomPreference(Context context) {
        super(context);
    }

    public CustomPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomPreference(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected View onCreateView(ViewGroup parent) {
        LayoutInflater viewInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        mRowView = viewInflater.inflate(R.layout.preferences_row_view, parent, false);

        mWidgetContainer = (LinearLayout) mRowView.findViewById(android.R.id.widget_frame);

        Button button = new Button(getContext());
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

        button.setLayoutParams(params);
        button.setBackgroundResource(R.drawable.listview_row_bg);
        button.setTextSize(14); …
Run Code Online (Sandbox Code Playgroud)

android android-preferences

5
推荐指数
1
解决办法
3234
查看次数

标签 统计

android ×1

android-preferences ×1