如何以编程方式重复工具栏背景图像?
How to repeat Toolbar background image programatically?
如何在运行时使用重复图像设置工具栏样式(不使用 xml 样式)?
在您的 onCreateOptionsMenu(Menu menu) 方法中,添加以下内容:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
Bitmap bmp = BitmapFactory.decodeResource(getResources(),R.drawable.IMAGE_TO_REPEAT);
BitmapDrawable bitmapDrawable = new BitmapDrawable(bmp);
bitmapDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
toolbar.setBackgroundDrawable(bitmapDrawable);
如何在运行时使用重复图像设置工具栏样式(不使用 xml 样式)?
在您的 onCreateOptionsMenu(Menu menu) 方法中,添加以下内容:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
Bitmap bmp = BitmapFactory.decodeResource(getResources(),R.drawable.IMAGE_TO_REPEAT);
BitmapDrawable bitmapDrawable = new BitmapDrawable(bmp);
bitmapDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
toolbar.setBackgroundDrawable(bitmapDrawable);