問題描述: 代碼TextView、Button調用setBackgroundResource將9.png/9-patch 圖片設置背景後文字不顯示
問題原因: 9.png/9-patch 圖片自帶內邊距
setBackgroundResource源碼圖解
解決辦法
TextView、Button在調用 setBackgroundResource方法之後,再調用 setPadding方法,示例如下
textview.setBackgroundResource(R.mipmap.img_bg_red);
textview.setPadding(20, 0, 20, 0)
經過測試,問題已解決。