精华内容
下载资源
问答
  • swing 替换标题图片与插入背景图片

    千次阅读 2017-03-05 20:19:53
    1.替换标题图片 Image img=Toolkit.getDefaultToolkit().getImage("img/2.jpg"); //用以接收图片的URL setIconImage(img);//获得图片2.Jpanel插入背景图片import java.awt.Graphics; import java.awt.Image;import ...

    1.替换标题图片

        Image img=Toolkit.getDefaultToolkit().getImage("img/2.jpg"); //用以接收图片的URL
        setIconImage(img);//获得图片

    2.Jpanel插入背景图片

    import java.awt.Graphics;
    import java.awt.Image;
    
    import javax.swing.JPanel;
    
    public class BackgroundPanel extends JPanel{
    
        /**
         * 
         */
        private static final long serialVersionUID = 916877989182209631L;
        private Image image=null;
        public BackgroundPanel(Image image)
        {
            this.image=image;
        }
         protected void paintComponent(Graphics g) {  
                g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), this);  // 固定背景图片,允许这个JPanel可以在图片上添加其他组件  
           }  
    }
    
    //
    Image image=new ImageIcon("img/1.jpg").getImage(); //插入图片
            JPanel jPanel1=new BackgroundPanel(image);//将图片写入jpanel1
    展开全文
  • jQuery仿京东通过商品标题切换背景图片特效,很不错的JS特效,适合在页面排版上的显示切换,颜色搭配非常漂亮大气。
  • 其它还好说,就是标题,不好弄。鼓捣了半天,终于搞定,先记下来,省得忘了。。 private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { if (e....

    datagridview很好用,但样子太差了。

    其它还好说,就是标题,不好弄。鼓捣了半天,终于搞定,先记下来,省得忘了。。

     
    private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
            {
                if (e.RowIndex == -1)
                {
                    int X = e.CellBounds.X;
                    int Y = e.CellBounds.Y;
                    int W = e.CellBounds.Width;
                    int H = e.CellBounds.Height;
    
                    Pen blackPen = new Pen(Color.FromArgb(195, 195, 195));//边框颜色
    
                    Image image = Properties.Resources._title1;//背景图片
                    TextureBrush tBrush = new TextureBrush(image);
    
                    e.Graphics.FillRectangle(tBrush, new Rectangle(X, Y, W, H));
    
                    if (e.ColumnIndex == 0)
                        e.Graphics.DrawRectangle(blackPen, new Rectangle(X, Y + 1, W - 1, H - 2));
                    else
                        e.Graphics.DrawRectangle(blackPen, new Rectangle(X - 1, Y + 1, W, H - 2));
    
                    e.PaintContent(e.CellBounds);
                    e.Handled = true;
                }
            }

     

    第一列。全选实现,园子里很多了。先放这。

    #region 重写复选框表头(实现全选)
    
            //实现全选的事件参数类
            public class DataGridviewCheckboxHeaderEventHander : EventArgs
            {
                private bool checkedState = false;
    
                public bool CheckedState
                {
                    get { return checkedState; }
                    set { checkedState = value; }
                }
            }
    
            //与事件关联的委托
            public delegate void DataGridviewCheckboxHeaderCellEventHander(object sender, DataGridviewCheckboxHeaderEventHander e);
    
            //重写 DataGridViewColumnHeaderCell
            public class DataGridviewCheckboxHeaderCell : DataGridViewColumnHeaderCell
            {
                private Point checkBoxLocation;
                private Size checkBoxSize;
                private bool isChecked = false;
                private Point cellLocation = new Point();
                private System.Windows.Forms.VisualStyles.CheckBoxState cbState = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal;
    
                public event DataGridviewCheckboxHeaderCellEventHander OnCheckBoxClicked;
    
    
                //绘制列头checkbox
                protected override void Paint(Graphics g,
                                              Rectangle clipBounds,
                                              Rectangle cellBounds,
                                              int rowIndex,
                                              DataGridViewElementStates dataGridViewElementState,
                                              object value,
                                              object formattedValue,
                                              string errorText,
                                              DataGridViewCellStyle cellStyle,
                                              DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                              DataGridViewPaintParts paintParts)
                {
                    base.Paint(g, clipBounds, cellBounds, rowIndex, dataGridViewElementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
                    Point p = new Point();
                    Size s = CheckBoxRenderer.GetGlyphSize(g, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal);
                    //列头checkbox的X坐标
                    p.X = cellBounds.Location.X + (cellBounds.Width / 2) - (s.Width / 2) - 1;
                    //列头checkbox的Y坐标
                    p.Y = cellBounds.Location.Y + (cellBounds.Height / 2) - (s.Height / 2);
                    cellLocation = cellBounds.Location;
                    checkBoxLocation = p;
                    checkBoxSize = s;
                    if (isChecked)
                        cbState = System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal;
                    else
                        cbState = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal;
                    //绘制复选框
                    CheckBoxRenderer.DrawCheckBox(g, checkBoxLocation, cbState);
                }
    
                /// <summary>
                /// 响应点击列头checkbox单击事件
                /// </summary>
                protected override void OnMouseClick(DataGridViewCellMouseEventArgs e)
                {
                    Point p = new Point(e.X + cellLocation.X, e.Y + cellLocation.Y);
                    if (p.X >= checkBoxLocation.X && p.X <= checkBoxLocation.X + checkBoxSize.Width && p.Y >= checkBoxLocation.Y && p.Y <= checkBoxLocation.Y + checkBoxSize.Height)
                    {
                        isChecked = !isChecked;
    
                        //获取列头checkbox的选择状态
                        DataGridviewCheckboxHeaderEventHander ex = new DataGridviewCheckboxHeaderEventHander();
                        ex.CheckedState = isChecked;
    
                        //此处不代表选择的列头checkbox,只是作为参数传递。应该列头checkbox是绘制出来的,无法获得它的实例
                        object sender = new object();
    
                        if (OnCheckBoxClicked != null)
                        {
                            //触发单击事件
                            OnCheckBoxClicked(sender, ex);
                            this.DataGridView.InvalidateCell(this);
                        }
    
                    }
                    base.OnMouseClick(e);
                }
            }
    
            #endregion

    然后在绑定事件后,加入

    DataGridviewCheckboxHeaderCell ch = new DataGridviewCheckboxHeaderCell();
                ch.OnCheckBoxClicked += new DataGridviewCheckboxHeaderCellEventHander(ch_OnCheckBoxClicked);  //关联单击事件
    
                //第一列为DataGridViewCheckBoxColumn
                DataGridViewCheckBoxColumn checkboxCol = this.dataGridView1.Columns[0] as DataGridViewCheckBoxColumn;
                //checkboxCol.ThreeState = true;
                checkboxCol.HeaderCell = ch;
                checkboxCol.HeaderCell.Value = string.Empty;//消除列头checkbox旁出现的文字
    void ch_OnCheckBoxClicked(object sender, Form2.DataGridviewCheckboxHeaderEventHander e)
            {
                foreach (DataGridViewRow dgvRow in this.dataGridView1.Rows)
                {
                    if (e.CheckedState)
                    {
                        dgvRow.Cells[0].Value = true;
                    }
                    else
                    {
                        dgvRow.Cells[0].Value = false;
                    }
                }
            }

     

    转载于:https://www.cnblogs.com/lclc88com/archive/2012/05/11/2496143.html

    展开全文
  • 先说下大体思路,先先创建 label 设置 字体和颜色... 这个 方法把图片转换成颜色, 最后设置UITableViewRowAction 背景色 就完成了 UIImage *(^GetImageWithView)(UIView *) = ^(UIView *view) { UIGraphicsBeginI...

    先说下大体思路,先先创建 label 设置 字体和颜色(也可以 是 imageview ) 。然后利用 UIGraphics 绘制成图片,然后利用

    + (UIColor *)colorWithPatternImage:(UIImage *)image; 这个 方法把图片转换成颜色, 最后设置 UITableViewRowAction 背景色 就完成了

    UIImage *(^GetImageWithView)(UIView *) = ^(UIView *view) {
      UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
      [view.layer renderInContext:UIGraphicsGetCurrentContext()];
      UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
      UIGraphicsEndImageContext();
      return image;
    };

    UIColor *(^getColorWithLabelText)(NSString *, UIColor *, UIColor *) = ^(NSString *text, UIColor *textColor, UIColor *bgColor) {

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 180, 80)];

        view.backgroundColor = bgColor;

        UILabel *actionLb = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 150, 80)];

        actionLb.font = [UIFont boldSystemFontOfSize:14];

        actionLb.text = text;

        actionLb.textColor = textColor;

        actionLb.textAlignment = NSTextAlignmentLeft;

        [view addSubview:actionLb];

        return [UIColor colorWithPatternImage:AddressimageWithView(view)];

    };

    在下面调用就可以了

     

     

     

    展开全文
  • Pivot 标题 背景图片

    2013-07-18 11:04:46
    大家好,在wpf建立一个Pivot Page 然后我想在程序运行时滑动到那个界面就将该界面的标题即默认为Item1的那个地方用红底白字显示或者一种图片作为背景但是他的内容不能更改,请问有什么方法或者思路吗?非常感谢!!...
  • Android沉浸式状态栏+图片背景+标题栏渐变+背景伸缩 PersonView 自定义ScrollView实现Toolbar(标题栏)渐变 效果如图: 编程思想: 1、自定义一个类,继承自ScrollView,并重写它的 onScrollChanged 方法; ...

    Android沉浸式状态栏+图片背景+标题栏渐变+背景伸缩

    今天做项目时,刚好用到了一部分Android沉浸式状态栏的技术,我就单独写了出来
    该部分代码在PersonView中
    首先是自定义ScrollView实现Toolbar(标题栏)渐变

    效果展示图:
    在这里插入图片描述
    编程思想:

    1、自定义一个类,继承自ScrollView,并重写它的 onScrollChanged 方法;

    2、在 onScrollChanged 中获取 ScrollView 在Y轴的移动距离,并根据此距离改变 Toolbar(标题栏) 的透明度。
    示例代码:
    类:MainActivity.java

    package com.example.personview;
    
    import android.os.Bundle;
    import android.support.annotation.Nullable;
    import android.view.Gravity;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.LinearLayout;
    import android.widget.Toast;
    
    import com.example.personview.base.BaseActivity;
    import com.example.personview.impl.ActionBarClickListener;
    import com.example.personview.widget.TranslucentActionBar;
    import com.example.personview.widget.TranslucentScrollView;
    
    
    /**
     * Created by Administrator
     * time:2019/8/13
     */
    
    public class MainActivity extends BaseActivity implements ActionBarClickListener, TranslucentScrollView.TranslucentChangedListener, View.OnClickListener {
    
        private TranslucentScrollView translucentScrollView;
        private TranslucentActionBar actionBar;
        private View zoomView;
    
        @Override
        protected void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            init();
            initClick();//初始化点击事件
        }
    
        private void init() {
            actionBar = (TranslucentActionBar) findViewById(R.id.actionbar);
            //初始actionBar
            actionBar.setData("个人中心", 0, null, 0, null, null);
            //开启渐变
            actionBar.setNeedTranslucent();
            //设置状态栏高度
            actionBar.setStatusBarHeight(getStatusBarHeight());
    
            translucentScrollView = (TranslucentScrollView) findViewById(R.id.pullzoom_scrollview);
            //设置透明度变化监听
            translucentScrollView.setTranslucentChangedListener(this);
            //关联需要渐变的视图
            translucentScrollView.setTransView(actionBar);
    
            zoomView = findViewById(R.id.lay_header);
            //关联伸缩的视图
            translucentScrollView.setPullZoomView(zoomView);
        }
    
        @Override
        public void onLeftClick() {
    
        }
    
        @Override
        public void onRightClick() {
    
        }
    
        @Override
        public void onTranslucentChanged(int transAlpha) {
            actionBar.tvTitle.setVisibility(transAlpha > 48 ? View.VISIBLE : View.GONE);
        }
    
        /**
         * 初始化点击事件
         * 获取布局文件toast_signtoday.xml里的控件
         **/
        private void initClick() {
            LinearLayout person_sign = (LinearLayout) findViewById(R.id.person_sign);
            person_sign.setOnClickListener(this);
            LinearLayout person_footprint = (LinearLayout) findViewById(R.id.person_footprint);
            person_footprint.setOnClickListener(this);
            LinearLayout person_publish = (LinearLayout) findViewById(R.id.person_publish);
            person_publish.setOnClickListener(this);
            LinearLayout person_photowall = (LinearLayout) findViewById(R.id.person_photowall);
            person_photowall.setOnClickListener(this);
            LinearLayout person_lucky = (LinearLayout) findViewById(R.id.person_lucky);
            person_lucky.setOnClickListener(this);
            LinearLayout person_invite = (LinearLayout) findViewById(R.id.person_invite);
            person_invite.setOnClickListener(this);
            LinearLayout person_set = (LinearLayout) findViewById(R.id.person_set);
            person_set.setOnClickListener(this);
        }
    
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.person_sign:
                    //签到
                    LayoutInflater inflater = getLayoutInflater();
                    View layout = inflater.inflate(R.layout.activity_toast_signtoday, null);
                    Toast toast = new Toast(getApplicationContext());
                    toast.setGravity(Gravity.CENTER, 0, 0);
                    toast.setDuration(Toast.LENGTH_LONG);
                    toast.setView(layout);
                    toast.show();
                    break;
                case R.id.person_footprint:
                    //足迹
                    Toast.makeText(this,"足迹",Toast.LENGTH_SHORT).show();
                    break;
                case R.id.person_publish:
                    //我发布的
                    Toast.makeText(this,"我发布的",Toast.LENGTH_SHORT).show();
                    break;
                case R.id.person_photowall:
                    //照片墙
                    Toast.makeText(this,"照片墙",Toast.LENGTH_SHORT).show();
                    break;
                case R.id.person_lucky:
                    //开始抽奖
                    Toast.makeText(this,"开始抽奖",Toast.LENGTH_SHORT).show();
                    break;
                case R.id.person_invite:
                    //邀请奖励
                    Toast.makeText(this,"邀请奖励",Toast.LENGTH_SHORT).show();
                    break;
                case R.id.person_set:
                    //设置
                    Toast.makeText(this,"设置",Toast.LENGTH_SHORT).show();
                    break;
            }
        }
    }
    
    

    TranslucentScrollView.java

    package com.example.personview.widget;
    
    import android.animation.ObjectAnimator;
    import android.animation.ValueAnimator;
    import android.content.Context;
    import android.graphics.Color;
    import android.support.annotation.ColorInt;
    import android.support.v4.graphics.ColorUtils;
    import android.util.AttributeSet;
    import android.util.Log;
    import android.view.MotionEvent;
    import android.view.View;
    import android.view.ViewGroup;
    import android.view.WindowManager;
    import android.widget.ScrollView;
    
    import com.example.personview.R;
    import com.example.personview.utils.SizeUtils;
    
    /**
     * Created by 晓辉(xiaohui)
     * time:2019/8/13
     */
    
    public class TranslucentScrollView extends ScrollView {
    
        static final String TAG = "TranslucentScrollView";
    
        //伸缩视图
        private View zoomView;
        //伸缩视图初始高度
        private int zoomViewInitHeight = 0;
        // 记录首次按下位置
        private float mFirstPosition = 0;
        // 是否正在放大
        private Boolean mScaling = false;
    
        //渐变的视图
        private View transView;
        //渐变颜色
        private int transColor = Color.WHITE;
        //渐变开始位置
        private int transStartY = 50;
        //渐变结束位置
        private int transEndY = 300;
    
        //渐变开始默认位置,Y轴,50dp
        private final int DFT_TRANSSTARTY = 50;
        //渐变结束默认位置,Y轴,300dp
        private final int DFT_TRANSENDY = 300;
    
        private TranslucentScrollView.TranslucentChangedListener translucentChangedListener;
    
        public interface TranslucentChangedListener {
            /**
             * 透明度变化,取值范围0-255
             *
             * @param transAlpha
             */
            void onTranslucentChanged(int transAlpha);
        }
    
        public TranslucentScrollView(Context context) {
            super(context);
        }
    
        public TranslucentScrollView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public TranslucentScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
        }
    
        public void setTranslucentChangedListener(TranslucentScrollView.TranslucentChangedListener translucentChangedListener) {
            this.translucentChangedListener = translucentChangedListener;
        }
    
        /**
         * 设置伸缩视图
         *
         * @param zoomView
         */
        public void setPullZoomView(View zoomView) {
            this.zoomView = zoomView;
            zoomViewInitHeight = zoomView.getLayoutParams().height;
            if (zoomViewInitHeight == LayoutParams.MATCH_PARENT || zoomViewInitHeight == WindowManager.LayoutParams.WRAP_CONTENT) {
                zoomView.post(new Runnable() {
                    @Override
                    public void run() {
                        zoomViewInitHeight = TranslucentScrollView.this.zoomView.getHeight();
                    }
                });
            }
        }
    
        /**
         * 设置渐变视图
         *
         * @param transView 渐变的视图
         */
        public void setTransView(View transView) {
            setTransView(transView, getResources().getColor(R.color.colorPrimary), SizeUtils.dip2px(getContext(), DFT_TRANSSTARTY), SizeUtils.dip2px(getContext(), DFT_TRANSENDY));
        }
    
        /**
         * 设置渐变视图
         *
         * @param transView  渐变的视图
         * @param transColor 渐变颜色
         * @param transEndY  渐变结束位置
         */
        public void setTransView(View transView, @ColorInt int transColor, int transStartY, int transEndY) {
            this.transView = transView;
            //初始视图-透明
            this.transView.setBackgroundColor(ColorUtils.setAlphaComponent(transColor, 0));
            this.transStartY = transStartY;
            this.transEndY = transEndY;
            this.transColor = transColor;
            if (transStartY > transEndY) {
                throw new IllegalArgumentException("transStartY 不得大于 transEndY .. ");
            }
        }
    
        /**
         * 获取透明度
         *
         * @return
         */
        private int getTransAlpha() {
            float scrollY = getScrollY();
            if (transStartY != 0) {
                if (scrollY <= transStartY) {
                    return 0;
                } else if (scrollY >= transEndY) {
                    return 255;
                } else {
                    return (int) ((scrollY - transStartY) / (transEndY - transStartY) * 255);
                }
            } else {
                if (scrollY >= transEndY) {
                    return 255;
                }
                return (int) ((transEndY - scrollY) / transEndY * 255);
            }
        }
    
        /**
         * 重置ZoomView
         */
        private void resetZoomView() {
            final ViewGroup.LayoutParams lp = zoomView.getLayoutParams();
            final float h = zoomView.getLayoutParams().height;// ZoomView当前高度
    
            // 设置动画
            ValueAnimator anim = ObjectAnimator.ofFloat(0.0F, 1.0F).setDuration(200);
    
            anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    float cVal = (Float) animation.getAnimatedValue();
                    lp.height = (int) (h - (h - zoomViewInitHeight) * cVal);
                    zoomView.setLayoutParams(lp);
                }
            });
            anim.start();
        }
    
        @Override
        protected void onScrollChanged(int l, int t, int oldl, int oldt) {
            super.onScrollChanged(l, t, oldl, oldt);
            int transAlpha = getTransAlpha();
    
            if (transView != null) {
                Log.d(TAG, "[onScrollChanged .. in ], 透明度 == " + transAlpha);
                transView.setBackgroundColor(ColorUtils.setAlphaComponent(transColor, transAlpha));
            }
            if (translucentChangedListener != null) {
                translucentChangedListener.onTranslucentChanged(transAlpha);
            }
        }
    
        @Override
        public boolean onTouchEvent(MotionEvent event) {
            if (zoomView != null) {
                ViewGroup.LayoutParams params = zoomView.getLayoutParams();
                switch (event.getAction()) {
                    case MotionEvent.ACTION_UP:
                        //手指离开后恢复图片
                        mScaling = false;
                        resetZoomView();
                        break;
                    case MotionEvent.ACTION_MOVE:
                        if (!mScaling) {
                            if (getScrollY() == 0) {
                                mFirstPosition = event.getY();
                            } else {
                                break;
                            }
                        }
    
                        int distance = (int) ((event.getY() - mFirstPosition) * 0.6);
                        if (distance < 0) {
                            break;
                        }
                        mScaling = true;
                        params.height = zoomViewInitHeight + distance;
    
                        Log.d(TAG, "params.height == " + params.height + ", zoomViewInitHeight == " + zoomViewInitHeight + ", distance == " + distance);
                        zoomView.setLayoutParams(params);
                        return true;
                }
            }
    
            return super.onTouchEvent(event);
        }
    
    }
    
    

    TranslucentActionBar.java

    package com.example.personview.widget;
    
    import android.content.Context;
    import android.text.TextUtils;
    import android.util.AttributeSet;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.LinearLayout;
    import android.widget.TextView;
    
    import com.example.personview.R;
    import com.example.personview.impl.ActionBarClickListener;
    
    /**
     * 支持渐变的 actionBar
     * Created by 晓辉(xiaohui)
     * time: 2019/8/13.
     */
    
    public final class TranslucentActionBar extends LinearLayout {
    
        private View layRoot;
        private View vStatusBar;
        private View layLeft;
        private View layRight;
        public TextView tvTitle;
        private TextView tvLeft;
        private TextView tvRight;
        private View iconLeft;
        private View iconRight;
    
        public TranslucentActionBar(Context context) {
            this(context, null);
        }
    
        public TranslucentActionBar(Context context, AttributeSet attrs) {
            super(context, attrs);
            init();
        }
    
        public TranslucentActionBar(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
        }
    
        private void init() {
            setOrientation(HORIZONTAL);
            View contentView = inflate(getContext(), R.layout.actionbar_trans, this);
            layRoot = contentView.findViewById(R.id.lay_transroot);
            vStatusBar = contentView.findViewById(R.id.v_statusbar);
            tvTitle = (TextView) contentView.findViewById(R.id.tv_actionbar_title);
            tvLeft = (TextView) contentView.findViewById(R.id.tv_actionbar_left);
            tvRight = (TextView) contentView.findViewById(R.id.tv_actionbar_right);
            iconLeft = contentView.findViewById(R.id.iv_actionbar_left);
            iconRight = contentView.findViewById(R.id.v_actionbar_right);
        }
    
        /**
         * 设置状态栏高度
         *
         * @param statusBarHeight
         */
        public void setStatusBarHeight(int statusBarHeight) {
            ViewGroup.LayoutParams params = vStatusBar.getLayoutParams();
            params.height = statusBarHeight;
            vStatusBar.setLayoutParams(params);
        }
    
        /**
         * 设置是否需要渐变
         */
        public void setNeedTranslucent() {
            setNeedTranslucent(true, false);
        }
    
        /**
         * 设置是否需要渐变,并且隐藏标题
         *
         * @param translucent
         */
        public void setNeedTranslucent(boolean translucent, boolean titleInitVisibile) {
            if (translucent) {
                layRoot.setBackgroundDrawable(null);
            }
            if (!titleInitVisibile) {
                tvTitle.setVisibility(View.GONE);
            }
        }
    
        /**
         * 设置标题
         *
         * @param strTitle
         */
        public void setTitle(String strTitle) {
            if (!TextUtils.isEmpty(strTitle)) {
                tvTitle.setText(strTitle);
            } else {
                tvTitle.setVisibility(View.GONE);
            }
        }
    
        /**
         * 设置数据
         *
         * @param strTitle
         * @param resIdLeft
         * @param strLeft
         * @param resIdRight
         * @param strRight
         * @param listener
         */
        public void setData(String strTitle, int resIdLeft, String strLeft, int resIdRight, String strRight, final ActionBarClickListener listener) {
            if (!TextUtils.isEmpty(strTitle)) {
                tvTitle.setText(strTitle);
            } else {
                tvTitle.setVisibility(View.GONE);
            }
            if (!TextUtils.isEmpty(strLeft)) {
                tvLeft.setText(strLeft);
                tvLeft.setVisibility(View.VISIBLE);
            } else {
                tvLeft.setVisibility(View.GONE);
            }
            if (!TextUtils.isEmpty(strRight)) {
                tvRight.setText(strRight);
                tvRight.setVisibility(View.VISIBLE);
            } else {
                tvRight.setVisibility(View.GONE);
            }
    
            if (resIdLeft == 0) {
                iconLeft.setVisibility(View.GONE);
            } else {
                iconLeft.setBackgroundResource(resIdLeft);
                iconLeft.setVisibility(View.VISIBLE);
            }
    
            if (resIdRight == 0) {
                iconRight.setVisibility(View.GONE);
            } else {
                iconRight.setBackgroundResource(resIdRight);
                iconRight.setVisibility(View.VISIBLE);
            }
    
            if (listener != null) {
                layLeft = findViewById(R.id.lay_actionbar_left);
                layRight = findViewById(R.id.lay_actionbar_right);
                layLeft.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        listener.onLeftClick();
                    }
                });
                layRight.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        listener.onRightClick();
                    }
                });
            }
        }
    
    }
    
    

    布局文件:activity_main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:app="http://schemas.android.com/apk/res-auto">
        <com.example.personview.widget.TranslucentScrollView
            android:id="@+id/pullzoom_scrollview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
                <LinearLayout
                    android:id="@+id/lay_header"
                    android:layout_width="match_parent"
                    android:layout_height="248dp"
                    android:background="@mipmap/bg_banner_my"
                    android:orientation="vertical">
                    <View
                        android:id="@+id/v_statusbar"
                        android:layout_width="match_parent"
                        android:layout_height="0.0dp"
                        android:background="@color/translate" />
                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">
                        <RelativeLayout
                            android:layout_width="137dp"
                            android:layout_height="137dp"
                            android:layout_centerInParent="true"
                            android:background="@mipmap/bg_avatar">
                            <de.hdodenhof.circleimageview.CircleImageView
                                android:id="@+id/image_head"
                                android:layout_width="105dp"
                                android:layout_height="105dp"
                                android:layout_centerInParent="true"
                                android:src="@mipmap/dft_avatar"
                                app:civ_border_color="#FFFFFF"
                                app:civ_border_width="1dp" />
                        </RelativeLayout>
                        <LinearLayout
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_alignParentBottom="true"
                            android:layout_centerHorizontal="true"
                            android:layout_marginBottom="15dp"
                            android:orientation="vertical">
                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:gravity="center">
                            <TextView
                                android:id="@+id/name"
                                style="@style/text_white"
                                android:layout_gravity="center_horizontal"
                                android:text="@string/name"
                                android:textColor="@color/white"
                                android:textSize="17sp" />
                        </LinearLayout>
                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:gravity="center">
                                <TextView
                                    android:id="@+id/frag4_age"
                                    android:layout_width="30dp"
                                    android:layout_height="22dp"
                                    android:background="@drawable/bg_person_left"
                                    android:gravity="center_horizontal"
                                    android:text="20"
                                    android:textSize="11sp" />
    
                                <ImageView
                                 android:id="@+id/frag4_sex"
                                 android:layout_width="30dp"
                                 android:layout_height="22dp"
                                 android:paddingRight="6dp"
                                 android:paddingTop="4dp"
                                 android:paddingBottom="2dp"
                                 android:background="@drawable/bg_person_right"
                                 android:src="@drawable/ic_person_man" />
                            </LinearLayout>
                        </LinearLayout>
                    </RelativeLayout>
                </LinearLayout>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/white"
                    android:orientation="horizontal"
                    android:paddingTop="8dp"
                    android:paddingBottom="8dp">
                    <LinearLayout
                        android:id="@+id/lay_car"
                        android:layout_width="0.0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1.0"
                        android:gravity="center_horizontal"
                        android:orientation="vertical">
                        <ImageView
                            android:layout_width="50dp"
                            android:layout_height="50dp"
                            android:scaleType="fitXY"
                            android:src="@mipmap/ic_shopcar_my" />
                        <TextView
                            style="@style/text_black"
                            android:layout_marginTop="5dp"
                            android:text="@string/contribute" />
                        <TextView
                            style="@style/text_black"
                            android:id="@+id/contribute"
                            android:layout_marginTop="5dp"
                            android:text="1000+" />
                    </LinearLayout>
                    <LinearLayout
                        android:id="@+id/lay_history"
                        android:layout_width="0.0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1.0"
                        android:gravity="center_horizontal"
                        android:orientation="vertical">
                        <ImageView
                            android:id="@+id/imageView"
                            android:layout_width="50dp"
                            android:layout_height="50dp"
                            android:scaleType="fitXY"
                            android:src="@mipmap/ic_consume_history" />
                        <TextView
                            style="@style/text_black"
                            android:layout_width="wrap_content"
                            android:layout_marginTop="5dp"
                            android:text="@string/grade" />
                        <TextView
                            style="@style/text_black"
                            android:id="@+id/grade"
                            android:layout_width="wrap_content"
                            android:layout_marginTop="5dp"
                            android:text="V10" />
                    </LinearLayout>
                    <LinearLayout
                        android:id="@+id/lay_wallet"
                        android:layout_width="0.0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1.0"
                        android:gravity="center_horizontal"
                        android:orientation="vertical">
                        <ImageView
                            android:layout_width="50dp"
                            android:layout_height="50dp"
                            android:scaleType="fitXY"
                            android:src="@mipmap/ic_wallet" />
                        <TextView
                            style="@style/text_black"
                            android:layout_marginTop="5dp"
                            android:text="@string/coin" />
                        <TextView
                            style="@style/text_black"
                            android:id="@+id/coin"
                            android:layout_marginTop="5dp"
                            android:text="500" />
                    </LinearLayout>
                </LinearLayout>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/white"
                    android:orientation="vertical">
                    <View
                        android:layout_width="match_parent"
                        android:layout_height="15dp"
                        android:background="@color/bg_main" />
                    <LinearLayout
                        android:id="@+id/person_sign"
                        android:layout_width="match_parent"
                        android:layout_height="55dp"
                        android:background="@color/white"
                        android:orientation="horizontal">
                        <ImageView
                            android:layout_width="15dp"
                            android:layout_height="15dp"
                            android:layout_gravity="center_vertical"
                            android:layout_marginLeft="16dp"
                            android:background="@mipmap/ic_sign" />
                        <TextView
                            style="@style/text_black"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical"
                            android:layout_marginLeft="17dp"
                            android:text="@string/sign" />
                        <TextView
                            android:id="@+id/tv_has_sign"
                            style="@style/text_black"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical"
                            android:layout_marginLeft="3dp"
                            android:layout_weight="1"
                            android:text="@string/sign"
                            android:textColor="@color/gray_dft"
                            android:textSize="13sp"
                            android:visibility="invisible" />
                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical"
                            android:layout_marginRight="16dp"
                            android:background="@mipmap/ic_right_gray" />
                    </LinearLayout>
                    <View
                        style="@style/horizontal_divider_light"
                        android:layout_marginLeft="16dp" />
                    <LinearLayout
                        android:id="@+id/person_footprint"
                        android:layout_width="match_parent"
                        android:layout_height="55dp"
                        android:background="@color/white"
                        android:orientation="horizontal">
                        <ImageView
                            android:layout_width="15dp"
                            android:layout_height="15dp"
                            android:layout_gravity="center_vertical"
                            android:layout_marginLeft="16dp"
                            android:background="@mipmap/ic_address" />
                        <TextView
                            style="@style/text_black"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical"
                            android:layout_marginLeft="17dp"
                            android:layout_weight="1"
                            android:text="@string/footprint" />
                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical"
                            android:layout_marginRight="16dp"
                            android:background="@mipmap/ic_right_gray" />
                    </LinearLayout>
                    <View
                        android:layout_width="match_parent"
                        android:layout_height="15dp"
                        android:background="@color/bg_main" />
                    <LinearLayout
                        android:id="@+id/person_publish"
                        android:layout_width="match_parent"
                        android:layout_height="55dp"
                        android:background="@color/white"
                        android:orientation="horizontal">
                        <ImageView
                            android:layout_width="15dp"
                            android:layout_height="15dp"
                            android:layout_gravity="center_vertical"
                            android:layout_marginLeft="16dp"
                            android:background="@mipmap/ic_agent_my" />
                        <TextView
                            style="@style/text_black"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical"
                            android:layout_marginLeft="17dp"
                            android:layout_weight="1"
                            android:text="@string/publish" />
                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical"
                            android:layout_marginRight="16dp"
                            android:background="@mipmap/ic_right_gray" />
                    </LinearLayout>
                    <View
                        style="@style/horizontal_divider_light"
                        android:layout_marginLeft="16dp" />
                    <LinearLayout
                        android:id="@+id/person_photowall"
                        android:layout_width="match_parent"
                        android:layout_height="55dp"
                        android:background="@color/white"
                        android:orientation="horizontal">
                        <ImageView
                            android:layout_width="15dp"
                            android:layout_height="15dp"
                            android:layout_gravity="center_vertical"
                            android:layout_marginLeft="16dp"
                            android:background="@mipmap/ic_teacher_my" />
                        <TextView
                            style="@style/text_black"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical"
                            android:layout_marginLeft="17dp"
                            android:layout_weight="1"
                            android:text="@string/photowall" />
                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical"
                            android:layout_marginRight="16dp"
                            android:background="@mipmap/ic_right_gray" />
                    </LinearLayout>
                    <View
                        android:layout_width="match_parent"
                        android:layout_height="15dp"
                        android:background="@color/bg_main" />
                    <LinearLayout
                        android:id="@+id/person_lucky"
                        android:layout_width="match_parent"
                        android:layout_height="55dp"
                        android:background="@color/white"
                        android:orientation="horizontal">
                        <ImageView
                            android:layout_width="15dp"
                            android:layout_height="15dp"
                            android:layout_gravity="center_vertical"
                            android:layout_marginLeft="16dp"
                            android:background="@mipmap/ic_luck_my" />
                        <TextView
                            style="@style/text_black"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical"
                            android:layout_marginLeft="17dp"
                            android:layout_weight="1"
                            android:text="@string/lucky" />
                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical"
                            android:layout_marginRight="16dp"
                            android:background="@mipmap/ic_right_gray" />
                    </LinearLayout>
                    <View
                        style="@style/horizontal_divider_light"
                        android:layout_marginLeft="16dp" />
                    <LinearLayout
                        android:id="@+id/person_invite"
                        android:layout_width="match_parent"
                        android:layout_height="55dp"
                        android:background="@color/white"
                        android:orientation="horizontal">
                        <ImageView
                            android:layout_width="15dp"
                            android:layout_height="15dp"
                            android:layout_gravity="center_vertical"
                            android:layout_marginLeft="16dp"
                            android:background="@mipmap/ic_invite_my" />
                        <TextView
                            style="@style/text_black"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical"
                            android:layout_marginLeft="17dp"
                            android:layout_weight="1"
                            android:text="@string/invite" />
                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical"
                            android:layout_marginRight="16dp"
                            android:background="@mipmap/ic_right_gray" />
                    </LinearLayout>
                    <View
                        android:layout_width="match_parent"
                        android:layout_height="15dp"
                        android:background="@color/bg_main" />
                    <LinearLayout
                        android:id="@+id/person_set"
                        android:layout_width="match_parent"
                        android:layout_height="55dp"
                        android:background="@color/white"
                        android:orientation="horizontal">
                        <ImageView
                            android:layout_width="15dp"
                            android:layout_height="15dp"
                            android:layout_gravity="center_vertical"
                            android:layout_marginLeft="16dp"
                            android:background="@mipmap/ic_set_my" />
                        <TextView
                            style="@style/text_black"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical"
                            android:layout_marginLeft="17dp"
                            android:layout_weight="1"
                            android:text="@string/set" />
                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical"
                            android:layout_marginRight="16dp"
                            android:background="@mipmap/ic_right_gray" />
                    </LinearLayout>
                    <View
                        android:layout_width="match_parent"
                        android:layout_height="140dp"
                        android:background="@color/bg_main" />
                </LinearLayout>
            </LinearLayout>
        </com.example.personview.widget.TranslucentScrollView>
        <com.example.personview.widget.TranslucentActionBar
            android:id="@+id/actionbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </RelativeLayout>
    

    activity_actionbar.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <com.example.personview.widget.TranslucentActionBar
            android:id="@+id/actionbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    
        <com.example.personview.widget.TranslucentScrollView
            android:id="@+id/scrollview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="1000dp"
                android:orientation="vertical" />
        </com.example.personview.widget.TranslucentScrollView>
    </LinearLayout>
    

    actionbar_trans.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/lay_transroot"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:orientation="vertical">
        <View
            android:id="@+id/v_statusbar"
            android:layout_width="match_parent"
            android:layout_height="1.0dp" />
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="45dp"
            android:orientation="vertical">
            <RelativeLayout
                android:id="@+id/lay_actionbar_left"
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:orientation="horizontal">
                <ImageView
                    android:id="@+id/iv_actionbar_left"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="10dp"
                    android:background="@mipmap/ic_left_light"
                    android:visibility="gone" />
                <TextView
                    android:id="@+id/tv_actionbar_left"
                    style="@style/text_white"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="10dp"
                    android:layout_toRightOf="@+id/iv_actionbar_left"
                    android:gravity="center_vertical"
                    android:maxLength="2"
                    android:singleLine="true"
                    android:text="返回"
                    android:visibility="gone" />
            </RelativeLayout>
            <TextView
                android:id="@+id/tv_actionbar_title"
                style="@style/text_white"
                android:layout_centerInParent="true"
                android:text="标题"
                android:textSize="16sp" />
            <RelativeLayout
                android:id="@+id/lay_actionbar_right"
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:layout_alignParentRight="true"
                android:gravity="right"
                android:orientation="horizontal">
                <View
                    android:id="@+id/v_actionbar_right"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_alignParentRight="true"
                    android:layout_centerVertical="true"
                    android:layout_marginRight="10dp"
                    android:visibility="gone" />
                <TextView
                    android:id="@+id/tv_actionbar_right"
                    style="@style/text_white"
                    android:layout_height="match_parent"
                    android:layout_marginRight="10dp"
                    android:layout_toLeftOf="@+id/v_actionbar_right"
                    android:gravity="center_vertical|right"
                    android:singleLine="true"
                    android:visibility="gone" />
            </RelativeLayout>
        </RelativeLayout>
    </LinearLayout>
    

    注意:全面屏要使标题栏渐变,除了需要在mainActivity.java里声明外,还要在AndroidManifest.xml中将theme设置成为android:theme="@style/TranslucentTheme";并且引入三个style样式文件,适应不同的机型。
    在这里插入图片描述
    好了核心代码就是这些,如下有项目完整包

    下载地址:https://download.csdn.net/download/qq_41894451/11538983

    展开全文
  • 自定义ScrollView实现Toolbar(标题栏)渐变效果如图: 编程思想:1、自定义一个类,继承自ScrollView,并重写它的 onScrollChanged 方法;2、在 onScrollChanged 中获取 ScrollView 在Y轴的移动距离,并根据此距离...
  • 可以单独切,把图片标题分开布局,不要当背景,当背景反而浪费更多时间来调整标题。高度和移动的图片也要统一。 这就是做背景,只写标题的问题,浪费很多时间,这个一定要分开布局,标题和img分开。 转载于...
  • 图片背景标题
  • 设置导航条背景图片 [navBar setBackgroundImage:[UIImage imageNamed: @" navigationbarBackgroundWhite " ] forBarMetrics:UIBarMetricsDefault]; }   转载于:...
  • 小程序顶部标题栏的背景图片设置

    千次阅读 2019-12-03 10:08:06
    实际运行结果为: ...此处我修改的页面是首页index.vue,我需要index的导航部分为图片背景。 所以,以下就以index.vue为例。 修改导航栏为自定义导航栏样式 修改需要配背景图片的页面路由的属性值,此...
  • 设置标题背景 1> 准备背景图片: background_pix.png 注:用背景图片比用颜色好处,可以让背景看起来有凹凸感. 2> drawable文件夹下放xml文件 bitmap_repeat.xml <?xml version=1.0 encoding=utf-8?> ...
  • 动态设置状态栏颜色为顶部标题背景图片颜色 package com.jibaowang.groupbuy.base; import android.content.Context; import android.content.Intent; import android.content.res.Configuration; import android....
  • 效果图 核心代码 此处用到了rich属性 title: { x: 'center', text: '{A| ' + that.... //设置背景图片,可以设置width和height,不设置时宽高自适应 backgroundColor: { image: require('../../assets/image
  • Android 标题背景渐变

    2016-12-08 15:43:19
    此demo是关于标题背景色默认的是全透明的,也就是以背景图片来作为背景色。然后随着ListView的滑动标题背景色会有全透明慢慢的变为和背景图一样的颜色。具体详情请前往博客查看...
  • 在webcontent里建个文件夹你把图片导进那个content的那个文件夹
  • Windows Terminal新版终端 美化设置背景图片标题

    万次阅读 多人点赞 2019-08-12 10:50:28
    自定义背景图片和颜色 "backgroundImage" : "T://2.jpg" , # 背景图片地址 "backgroundImageOpacity" : 0.9 #透明度 配置修改方法 点击设置,用vscode或者其他编辑器打开json配置文件 ...
  • 主要介绍了Android编程中聊天页面背景图片标题栏由于键盘引起问题的解决方法,针对键盘弹出时标题栏及背景图片异常的相关解决方法,具有一定参考借鉴价值,需要的朋友可以参考下
  • From google: If your app uses a custom image as the background of the bar,...一句话:将原来的44(88)像素的背景图片改为64(128)像素高度的图片即可。 转载于:https://www.cnblogs.com/ilovewindy/p/3977912.html
  • 上部分图片与底下没有对齐。 这个网站是随书给的例子,讲解不是很全。...然后图片能正常显示了,但“设为主页”就跑到图片下面去了。这感觉是个投机的做法,不对。 新手,正在学习中,请大神帮忙一下,谢谢。

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 4,589
精华内容 1,835
关键字:

标题图片背景