即使没有附加侦听器,也会调用添加全局布局侦听器,在这种情况下它会进入循环,如何编辑属性而不在循环中触发全局布局侦听器?谢谢
final View getDecorView = activity.getWindow().getDecorView();
getDecorView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT > 16) {
getDecorView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
} else {
getDecorView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
final TextView textView3 = (TextView) decorView.findViewById(2131558456);
if (textView3 != null) {
textView3.setText("updated"); textView3.setBackgroundColor(Color.parseColor("#444444"));
}
getDecorView.getViewTreeObserver().addOnGlobalLayoutListener(this);
}
});
Run Code Online (Sandbox Code Playgroud) var app = require("express")();
var server = require("http").Server(app);
var io = require("socket.io")(server);
var requestIp = require('request-ip');
server.listen(3000);
var ipMiddleware = function(req, res) {
return requestIp.getClientIp(req);
};
var ip = null;
app.get("/", function (req, res) {
ip = ipMiddleware(req, res);
res.sendFile(__dirname + "/index.html");
});
io.on("connection", function (socket) {
// send the ip to user
});
Run Code Online (Sandbox Code Playgroud)
我的问题是,我想用快递获取客户端的IP地址并向客户端发出ip地址,ips是不同的那么它应该是,我怎样才能发出我用快递得到的ip?谢谢
我有一个像这样的xml,当我显示抽屉布局时,它覆盖Toolbar,我希望我的抽象布局在我的下方Toolbar,我无法弄清楚如何做到这一点,我尝试了很多东西,我整天都在尝试.如何CoordinatorLayout在DrawerLayout不重叠的情况下使用Toolbar?
这是我的操作栏样式:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/ColorPrimary</item>
<item name="colorPrimaryDark">@color/ColorPrimaryDark</item>
<item name="colorAccent">@color/ColorPrimary</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawerLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="@+id/toolBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/ColorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<TextView
android:id="@+id/toolBarTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textColor="@color/white"
android:textSize="18dp"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
app:elevation="4dp"
app:fabSize="normal"
app:layout_behavior="com.frt.poppcar.utils.FabBehavior"/>
</android.support.design.widget.CoordinatorLayout>
<ScrollView
android:id="@+id/drawerList"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:background="@color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" …Run Code Online (Sandbox Code Playgroud)