变化的响应文本的颜色在我的片段 - 在Android的选择标记 [英] Change color of response text on my snippet - on selecting the marker in android

查看:208
本文介绍了变化的响应文本的颜色在我的片段 - 在Android的选择标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作与谷歌地图标记的android,看看下面

图像

我想改变Y'放大器的颜色; n按响应,就像如果是Y I想要的颜色应该是绿色和放大器;如果它是N那么颜色应该是红色。

现在这两个Y'放大器; N为红色,因为我已经写了下面的code:

 <的TextView
            机器人:ID =@ + ID /响应
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_marginLeft =5DP
            机器人:layout_toRightOf =@ ID / response_lbl
            机器人:textAllCaps =真
            机器人:文字颜色=@彩色/ event_response_s
            机器人:TEXTSIZE =18sp/>

在哪里event_response_s = RED。

这个我试过通过删除机器人:文字颜色=@色/ event_response_s
XML code。

 如果(marker.getSnippet()。等于(currentEvent.getButton_one())){       response.setTextColor(context.getResources()的getColor(R.color.green));
    }
    别的response.setTextColor(context.getResources()的getColor(R.color.red));

(marker.getSnippet的

值)为Y或N,取决于按钮用户将preSS。我想currentEvent.getButton_one();,这给第一个按钮的值进行检查。
这里的问题是我在其他类获得currentEvent.getButton_one()的正确值在声明而不​​是在其他类,即CustomInfoWindow。最后一个条件应该检查​​是这样的:如果Y ==Ÿ--->绿色盛着红色

请让我知道如果你需要了解更多信息或知道还有什么我都试过了。

在Event.java:

 意向书I =新意图(getApplicationContext(),MyActivity.class);
i.putExtra(response1,currentEvent.getButton_one());

在MainActivity.java:

 字符串response_1 = getIntent()getStringExtra(response1);

现在从MyActivity.java我必须使用response_1在CustomInfoWinidow.java进行比较:

 如果(marker.getSnippet()。等于(response_1)){
    response.setTextColor(context.getResources()的getColor(R.color.green));
}其他
   response.setTextColor(context.getResources()的getColor(R.color.red));
}


解决方案

编辑:尝试传递response_1到 CustomInfoWindow

的构造函数

 公共类CustomInfoWindow实现InfoWindowAdapter {公共静态最后弦乐DEVICE_ACTIVE =设备激活;私人字符串response_1; //添加为成员变量// .......
公共CustomInfoWindow(上下文的背景下,字符串response_1_custom){
  this.response_1 = response_1_custom; //此处设置的值
  this.context =背景;
  吹气=(LayoutInflater)LayoutInflater.from(背景);
}公共查看getInfoContents(标记标记){// ........
//现在这应该工作:
尝试{
如果(marker.getSnippet()。等于(response_1)){
response.setTextColor(context.getResources()的getColor(R.color.green));
}其他response.setTextColor(context.getResources()的getColor(R.color.red));
}赶上(例外五){}
如果(marker.getSnippet()。等于(DEVICE_ACTIVE)){
response.setTextColor(context.getResources()的getColor(R.color.red));
}
response.setText(marker.getSnippet());
返回视图。
}
// .....................

然后在MainActivity.java,传递 response_1 当你创建 CustomInfoWindow

 如果(user_id.equalsIgnoreCase(用户ID)){
  map.setInfoWindowAdapter(新CustomInfoWindow(getBaseContext(),response_1)); //添加response_1到构造函数的参数
  map.moveCamera(CameraUpdateFactory.newLatLngZoom(PERTH,12));
}

原来的答复:

我得到了它的使用相结合的工作 InfoWindowAdapter MarkerClickListener

基本上,你需要设置在 InfoWindowAdapter ,并设定标记的颜色 MarkerClickListener

  mGoogleMap.setOnMarkerClickListener(新GoogleMap.OnMarkerClickListener(){            @覆盖
            公共布尔onMarkerClick(标记标记){                Log.d(标记,标记,点击);                字符串s = marker.getSnippet();
                Log.d(标记,片段:+ S);                如果(s.equals(Y)){
                    marker.setIcon(BitmapDesc​​riptorFactory.defaultMarker(BitmapDesc​​riptorFactory.HUE_GREEN));                }
                否则如果(s.equals(N)){
                   marker.setIcon(BitmapDesc​​riptorFactory.defaultMarker(BitmapDesc​​riptorFactory.HUE_RED));
                }                返回false;            }        });        mGoogleMap.setInfoWindowAdapter(新GoogleMap.InfoWindowAdapter(){            //使用默认信息窗口框架
            @覆盖
            公共查看getInfoWindow(标记为arg0){
                返回null;
            }            //定义信息窗口的内容
            @覆盖
            公共查看getInfoContents(标记为arg0){                视图V = getLayoutInflater()膨胀(R.layout.customlayout,NULL);                //设置等领域.....                //片段:
                TextView的tSnippet =(TextView中)v.findViewById(R.id.snippet);                如果(arg0.getSnippet()。等于(N)){
                    tSnippet.setTextColor(Color.RED);                }
                否则如果(arg0.getSnippet()。等于(Y)){
                    tSnippet.setTextColor(Color.GREEN);
                }                返回伏;            }
        });

结果:

I am working on android with google map marker, look at the images below

I want to change the color of Y & N according to the response, like if it is Y I want the color should be GREEN & if it is N then the color should be RED.

Right now both Y & N are having RED color because I have written following code:

<TextView
            android:id="@+id/response"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_toRightOf="@id/response_lbl"
            android:textAllCaps="true"
            android:textColor="@color/event_response_s"
            android:textSize="18sp" />

Where event_response_s = RED.

I tried this by removing the android:textColor="@color/event_response_s" xml code.

    if (marker.getSnippet().equals(currentEvent.getButton_one())) { 

       response.setTextColor(context.getResources().getColor(R.color.green)); 
    } 
    else response.setTextColor(context.getResources().getColor(R.color.red));

Value of marker.getSnippet() is either Y or N, depends on the button user will press. I want to check this with currentEvent.getButton_one();, which gives value of 1st button. Problem here is I am getting correct value of currentEvent.getButton_one() in other class where it is declared but not in other class i.e. CustomInfoWindow. Final condition should check like this: if Y == Y ---> GREEN else RED.

Please let me know if you need more information or to know what else I have tried.

In Event.java:

Intent i = new Intent(getApplicationContext(), MyActivity.class);  
i.putExtra("response1", currentEvent.getButton_one());

In MainActivity.java:

String response_1 = getIntent().getStringExtra("response1");

Now from MyActivity.java I have to use response_1 in CustomInfoWinidow.java for comparison:

if (marker.getSnippet().equals(response_1)) { 
    response.setTextColor(context.getResources().getColor(R.color.green)); 
} else  
   response.setTextColor(context.getResources().getColor(R.color.red));
}

解决方案

Edit: Try passing in response_1 into the constructor of CustomInfoWindow

public class CustomInfoWindow implements InfoWindowAdapter { 

public static final String DEVICE_ACTIVE = "Device Active"; 

private String response_1; //Add this as a member variable

//.......


public CustomInfoWindow(Context context, String response_1_custom) {
  this.response_1 = response_1_custom; //set the value here 
  this.context = context; 
  inflater = (LayoutInflater) LayoutInflater.from(context); 
} 

public View getInfoContents(Marker marker) { 

//........


//Now this should work:
try { 
if (marker.getSnippet().equals(response_1)) { 
response.setTextColor(context.getResources().getColor(R.color.green)); 
} else response.setTextColor(context.getResources().getColor(R.color.red)); 
}catch(Exception e){ 

} 
if (marker.getSnippet().equals(DEVICE_ACTIVE)) { 
response.setTextColor(context.getResources().getColor(R.color.red)); 
} 
response.setText(marker.getSnippet()); 
return view; 
} 
//.....................

Then in MainActivity.java, pass in response_1 when you create the CustomInfoWindow:

if (user_id.equalsIgnoreCase(userid)) { 
  map.setInfoWindowAdapter(new CustomInfoWindow(getBaseContext(), response_1)); //added response_1 to constructor parameter
  map.moveCamera(CameraUpdateFactory.newLatLngZoom(PERTH, 12)); 
} 

Original answer:

I got it to work using a combination of a InfoWindowAdapter and a MarkerClickListener.

Basically, you need to set the text color of the snippet in the InfoWindowAdapter, and set the color of the Marker in the MarkerClickListener

      mGoogleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {

            @Override
            public boolean onMarkerClick(Marker marker) {

                Log.d("marker", "marker click");

                String s =  marker.getSnippet();
                Log.d("marker", "snippet: " + s);

                if (s.equals("Y")){
                    marker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));

                }
                else if (s.equals("N")){
                   marker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
                }

                return false;

            }

        });



        mGoogleMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

            // Use default InfoWindow frame
            @Override
            public View getInfoWindow(Marker arg0) {
                return null;
            }

            // Defines the contents of the InfoWindow
            @Override
            public View getInfoContents(Marker arg0) {

                View v = getLayoutInflater().inflate(R.layout.customlayout, null);

                //set other fields.....

                //Snippet:
                TextView tSnippet = (TextView) v.findViewById(R.id.snippet);

                if (arg0.getSnippet().equals("N")){
                    tSnippet.setTextColor(Color.RED);

                }
                else if (arg0.getSnippet().equals("Y")){
                    tSnippet.setTextColor(Color.GREEN);
                }

                return v;

            }
        });

Result:

这篇关于变化的响应文本的颜色在我的片段 - 在Android的选择标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆