设置View只显示透明下边框、透明背景框、阴影背景框的方法

实现的效果如下:

 

下面的代码是实现一个带边框的xml,很常见

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    
	<solid android:color="@android:color/transparent" />
	
	<stroke android:width="1dp" android:color="#FFFF0000" />
	 
	<corners android:radius="0dp" />
</shape>


下面是只显示下边框的xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    
	<solid android:color="@android:color/transparent" />
	
	<stroke android:width="1dp" android:color="#FFFF0000" />
	 
	<corners android:radius="0dp" />
</shape>


下面是显示阴影效果的背景

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Bottom 2dp Shadow -->
    <item>
        <shape  android:shape="rectangle">
            <solid android:color="#BBB" />
            <corners android:radius="5dp" />         
        </shape>
    </item>
    
    <!-- White Top color -->
    <item android:bottom="3px">
        <shape  android:shape="rectangle">
             <solid android:color="#FFE0EEEE" />
             <corners android:radius="5dp" />
             <padding
                android:top="15dp"
                android:right="15dp"
                android:bottom="15dp"
                android:left="15dp"/>
        </shape>       
    </item>
</layer-list>


点击设置他们的背景颜色吧:

	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.btnShowCountTimer :
				new MyCountTimer(120000, 1000, btnShowCountTimer).start();
				break;
			case R.id.btnBgBoard :
				btnBgBoard.setBackgroundResource(R.drawable.board);
				break;
			case R.id.btnOnlyShowLineBottom :
				btnOnlyShowLineBottom.setBackgroundResource(R.drawable.board_only_bottom_line);
				break;
			case R.id.btnShowLayers :
				btnShowLayers.setBackgroundResource(R.drawable.board_layers);
				break;
			default :
				break;
		}
	}


 


 

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页