我有一个带有自定义弹出菜单的微调器。这个弹出菜单有圆角。当您点击微调器中的选项时,它会显示波纹背景动画,但波纹会超出圆角并形成一个正常的矩形。我怎样才能使波纹保持在圆角矩形的边界内?
弹出背景:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/primaryLight2"/>
<corners android:radius="4dp"/>
Run Code Online (Sandbox Code Playgroud)
纺纱机:
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginStart="4dp"
android:gravity="start|center_vertical"
android:popupBackground="@drawable/background_spinner_popup"
android:textColor="@color/primaryText"
android:textSize="18sp"/>
Run Code Online (Sandbox Code Playgroud)
下拉项:
<TextView android:id="@android:id/text1"
style="@style/spinnerDropDownItemStyle"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:padding="8dp"
android:textSize="18sp"
android:background="@drawable/background_spinner_item_dropdown"
android:singleLine="true"
android:textColor="@color/white"/>
Run Code Online (Sandbox Code Playgroud)
下拉项背景:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<!-- Default background -->
<item>
<shape android:shape="rectangle">
<corners android:radius="4dp"/>
</shape>
</item>
<!-- Ripple bounds -->
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<corners android:radius="4dp"/>
</shape>
</item>
Run Code Online (Sandbox Code Playgroud)
设置微调器:
final Spinner spinner = (Spinner) rootView.findViewById(R.id.spinner);
ArrayAdapter arrayAdapter = ArrayAdapter.createFromResource(MainActivity.context, R.array.spinner, R.layout.item_spinner);
arrayAdapter.setDropDownViewResource(R.layout.item_spinner_dropdown); …Run Code Online (Sandbox Code Playgroud) 我想使用 androidVpnService来捕获数据包并根据 IP 地址过滤它们。我可以很好地从“tun”接口获取数据包,但之后我不确定如何将它们转发到原始目的地。根据这个答案的评论,我似乎只需要:
我尝试像这样发送数据:
Socket socket = new Socket();
socket.bind(new InetSocketAddress(0));
if (protect(socket)){
Log.e(TAG, "Socket protected");
}else{
Log.e(TAG, "Socket NOT protected");
}
socket.connect(new InetSocketAddress(ipPacket.getDestinationIp(), ipPacket.getDstPort()));
Log.e(TAG, "Socket connected: " + socket.isConnected());
socket.getOutputStream().write(getTCPHeader(getIpHeader(packet)[1])[1].array());
Run Code Online (Sandbox Code Playgroud)
getTCPHeader(ByteArray packet)这些方法getIpHeader(ByteArray packet)简单地将数据包分成两个,ByteArray如下所示:
private ByteBuffer[] getIpHeader(ByteBuffer packet){
packet.position(0);
ByteBuffer ipHeader = ByteBuffer.allocate(20);
ByteBuffer data = ByteBuffer.allocate(packet.limit() - 20);
packet.get(ipHeader.array(), 0, 20);
packet.get(data.array(), 0, packet.limit() - 20); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用名为的属性创建自定义视图borderWidth。当我尝试运行我的应用程序时,出现错误:
E:\ Android Studio Projects \ MyApp \ app \ build \ intermediates \ res \ merged \ debug \ values \ values.xml错误:(341)属性“ borderWidth”已经定义
在values.xml它指向的文件中,我可以看到它borderWidth已经被用于默认值FloatingActionButton和其他几个默认android小部件:
<style name="Widget.Design.FloatingActionButton" parent="android:Widget">
<item name="android:background">@drawable/design_fab_background</item>
<item name="backgroundTint">?attr/colorAccent</item>
<item name="fabSize">auto</item>
<item name="elevation">@dimen/design_fab_elevation</item>
<item name="pressedTranslationZ">@dimen/design_fab_translation_z_pressed</item>
<item name="rippleColor">?attr/colorControlHighlight</item>
<item name="borderWidth">@dimen/design_fab_border_width</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我可以在视图中重用该名称还是必须重命名?
编辑
这是整个attrs.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--<attr name="borderWidth" format="float" />-->
<declare-styleable name="ScrollingLineGraph">
<attr name="unitsX" format="float" />
<attr name="unitsY" format="float" />
<attr name="scaleY" format="float" />
<attr name="scaleX" …Run Code Online (Sandbox Code Playgroud)