我想要点击custom info window时出现marker。
我希望它是这样的:
ImageView
TextView
TextView
TextView
Button Button
Run Code Online (Sandbox Code Playgroud)
我看到了其他人对此的帖子问题,但仍然令人困惑。
android google-maps infowindow google-maps-markers android-button
我有两个按钮,我想将它们的形状更改为半圆形。然后将它们并排放置成一个完整的圆圈。已附加图像以显示我想要的按钮外观。任何帮助将不胜感激。谢谢。

我有一个带有涟漪效果的按钮,并希望在启用/禁用按钮时为背景颜色添加一个状态选择器。
state_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/green" android:state_enabled="true"/>
<item android:color="@color/grey" android:state_enabled="false"/>
</selector>
Run Code Online (Sandbox Code Playgroud)
涟漪.xml:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item android:id="@android:id/mask" android:drawable="@android:color/white" />
<item android:id="@android:id/background" android:drawable="@drawable/state_selector" />
</ripple>
Run Code Online (Sandbox Code Playgroud)
按钮.xml:
<Button
android:background="@drawable/ripple"
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
Run Code Online (Sandbox Code Playgroud)
但是应用程序在使用以下内容呈现时崩溃:
Resources$NotFoundException: Drawable drawable/ripple with resource ID #0x7f070071
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ripple.xml from drawable resource ID #0x7f070071
Run Code Online (Sandbox Code Playgroud)
和
android.content.res.Resources$NotFoundException: Drawable drawable/state_selector with resource ID #0x7f070075
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/state_selector.xml from drawable resource ID #0x7f070075
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙解决这个问题吗?谢谢
前 5 个按钮以编程方式添加,最后一个按钮通过 XML 添加。两种方式我都使用相同的参数。为什么动态添加的按钮文本会被截断?
程序化:
Button b = new Button(getActivity());
b.setText(text);
b.setAllCaps(false);
b.setBackgroundResource(R.drawable.button_tag_rect);
b.setTextColor(getResources().getColor(R.color.colorWhiteText));
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
dpToPx(28));
int marginInPx = dpToPx(2);
params.setMargins(marginInPx, marginInPx, marginInPx, marginInPx);
tagCloudTwitter.addView(b, tagCloudTwitter.getChildCount()-1, params);
Run Code Online (Sandbox Code Playgroud)
XML:
<Button
android:layout_width="wrap_content"
android:layout_height="28dp"
android:layout_margin="2dp"
android:textAllCaps="false"
android:background="@drawable/button_tag_rect"
android:textColor="@color/colorWhiteText"
android:text="test"/>
Run Code Online (Sandbox Code Playgroud)
编辑:解决了!请参阅下面我的回答。
我正在android中创建一个要求性别的表单。为了获得这个输入,我使用了包含两个按钮的 Material Button Toggle Group。我不知道如何知道在我的 activity.java 中点击了哪个按钮。如何了解我的活动中选定的按钮,以便我可以将详细信息保存在不同的数据库中。
xml文件
<com.google.android.material.button.MaterialButtonToggleGroup
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:singleSelection="true">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:layout_marginStart="5dp"
style="?attr/materialButtonOutlinedStyle"/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:layout_marginStart="10dp"
style="?attr/materialButtonOutlinedStyle"/>
</com.google.android.material.button.MaterialButtonToggleGroup>
Run Code Online (Sandbox Code Playgroud)
我的活动.java
MaterialButtonToggleGroup toggleButton = findViewById(R.id.toggleButton);
toggleButton.addOnButtonCheckedListener();
// I CAN'T FIND ANY PROPER SOLUTION
Run Code Online (Sandbox Code Playgroud) java android android-layout android-button material-components-android
我正在尝试在代码中更改按钮的颜色,如下所示
btn_no5.setTextColor(0x8E35EF);
Run Code Online (Sandbox Code Playgroud)
上述变化未反映(紫色),执行上述代码后文本消失.但是,如果我使用xml中的颜色反映它.那么如何通过java改变这个呢?
我已经阅读了关于这个主题的一些问题和答案,但没有一个适用于我的问题.
我的问题在于以下代码:
public class Activity2 extends Activity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.alt);
}
public void buttonPress(View v){
TextView tv1 = (TextView) findViewById(R.id.text1);
TextView tv2 = (TextView) findViewById(R.id.text2);
Button b1 = (Button) findViewById(R.id.button1);
if((tv1 != null) & (tv2 != null) & (b1 != null)){
tv1.setText(R.string.changed);
tv2.setText(R.string.changed);
b1.setText(R.string.changed);
}
else
Toast.makeText(getApplicationContext(), "VIEW ELEMENTS ARE NOT BEING ASSIGNED", Toast.LENGTH_SHORT).show();
}
Run Code Online (Sandbox Code Playgroud)
alt.xml看起来像这样
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:name="@+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/stuff" />
<TextView
android:name="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/stuff2" />
<Button …Run Code Online (Sandbox Code Playgroud) 当我点击它时,如何让我的ImageButton改变它的颜色?
我想做这样的事情:
按钮(蓝色) - >单击 - >按钮(红色) - >单击 - >按钮(蓝色) - >单击 - >按钮(红色)
当我点击它切换颜色,当我再次点击它回到原始.
我试过这样做:
mTrashFlag = !mTrashFlag;
ImageButton bt = (ImageButton)findViewById(R.id.trash_button);
if(!mTrashFlag)
{
bt.setBackgroundColor(0x4CB8FB);
}
else
{
bt.setBackgroundColor(0xff0000);
}
Run Code Online (Sandbox Code Playgroud)
但它没有用.它将颜色变为白色,然后我无法再次点击它.
我想制作一个自定义切换按钮,例如当我点击按钮时,星形会亮起,当我再次点击时,星形会关闭.我尝试了一些代码,但是他们将按钮更改为图像,当我点击它时,图像会发生变化.我的意思是,没有按钮,它只是一个图像.
我希望图像在按钮内部,就像默认切换按钮一样,我只需要更改其中的图像.
我怎么能这样做?
谢谢
我试图删除我的一个操作栏项目(设置菜单)并添加另一个,但它没有将正确的图标/操作添加到操作栏.
我的布局文件如下
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:icon="@drawable/settings"
android:showAsAction="always" />
</menu>
Run Code Online (Sandbox Code Playgroud)
我正在这样初始化它
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDefaultDisplayHomeAsUpEnabled(false);
actionBar.setHomeButtonEnabled(true);
actionBar.setTitle(mTitle);
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
Run Code Online (Sandbox Code Playgroud)
它显示了三个安卓点而不是我自己的图标(它也将它放在下拉列表中我想要更改红色圆圈中的点
我究竟做错了什么
android ×10
android-button ×10
android-ui ×1
android-xml ×1
colors ×1
google-maps ×1
infowindow ×1
java ×1
material-components-android ×1
xml ×1