标签: android-imagebutton

如何以编程方式设置app:srcCompat ="@ drawable/pic"的ImageButton属性?

如何设置ImageButton属性

app:srcCompat="@drawable/pic"
Run Code Online (Sandbox Code Playgroud)

编程?

像是myImageButton.setBackgroundResource(R.drawable.eng2);属性的东西app:srcCompat.

android android-appcompat android-imagebutton

56
推荐指数
2
解决办法
3万
查看次数

37
推荐指数
2
解决办法
3万
查看次数

有没有办法在Android RelativeLayout中填充父减去一个固定数字?

我有一个ImageButton我想填充其父RelativeLayout容器的宽度,但减去一些,dp所以它有一些左右填充.我试过,fill_parent-10dp但这会导致错误并且不会渲染.

android fill-parent android-imagebutton android-relativelayout

32
推荐指数
2
解决办法
2万
查看次数

在ImageButton外部实现Ripple效果

我正在尝试为ImageButton实现涟漪效果.我已经在src中设置了背景中的波纹和src中的可绘制图像.

android:background="@drawable/myripplexml"
android:src="@drawable/myimagepath"
Run Code Online (Sandbox Code Playgroud)

它在按钮布局内给出了很好的涟漪效果.但是我希望Ripple效果也能扩展到Button Layout之外.另一种方法是使用:

 android:background="?android:attr/selectableItemBackgroundBorderless"
Run Code Online (Sandbox Code Playgroud)

但它使用默认颜色和样式.如何定制颜色,形状和尺寸?

android android-imagebutton rippledrawable android-5.0-lollipop

30
推荐指数
3
解决办法
2万
查看次数

Android ImageButton setColorFilter不工作

我已经找到了回答这个问题的帖子,但是没有一个能为我工作,所以我认为我对它应该如何运作有一个根本的误解.我有一个ImageButton,它有一个png文件.除白色箭头外,png大多是透明的.我想用setColorFilter为箭头着色:

imageButton.setColorFilter(Color.argb(255, 225, 0, 0));
Run Code Online (Sandbox Code Playgroud)

但这没有任何影响.我已尝试使用各种Porter-Duff模式的setColorFilter版本,但这些都没有.关于问题可能是什么或者我可能缺少什么的任何想法将不胜感激.

android android-imagebutton

7
推荐指数
1
解决办法
5929
查看次数

对象不是抽象的,也没有实现抽象成员 public Abstract fun onClick(p0: View!): Unit

在过去的一天中,我没有找到任何显示如何执行此操作的内容,我所看到的所有内容都带有一个基本按钮,我无法复制该按钮以与图像按钮一起使用。使用 setOnClickListener 似乎根本不起作用,尽管我发现使用它们的唯一案例已经有 5 年多了。

Android Studio 中是否有相当于链接活动的 Storyboard?

这是我发现的一个 7 年前的例子。

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val myButton =
            findViewById<View>(R.id.live) as ImageButton

        myButton.setOnClickListener(object : OnClickListener() {
            // When the button is pressed/clicked, it will run the code below
            fun onClick() {
                // Intent is what you use to start another activity
                val intent = Intent(this, LiveActivity::class.java)
                startActivity(intent)
            }
        })
    }
}
Run Code Online (Sandbox Code Playgroud)

给出以下错误:

Object is not abstract and does not implement abstract member …
Run Code Online (Sandbox Code Playgroud)

android android-layout kotlin android-imagebutton

7
推荐指数
1
解决办法
2万
查看次数

如何在Android中制作彼此重叠的自定义形状按钮

我有6个单独的图像与透明背景.如何将所有这些图像组合在一起作为按钮,如:

在此输入图像描述

从我读到的,我想我必须使用框架布局,以便有重叠的按钮.

点击时我需要每种颜色都是一个单独的按钮.

更新:我做了一个演示并检查onclick方法中的透明然而当我点击红色和蓝色交叉点附近的红色区域时,由于重叠视图,它没有注册红色按钮是单击.请帮忙!

https://www.dropbox.com/s/fc98nnnfbrtdh82/Photo%20Apr%2016%2C%202%2002%2013.jpg?dl=0

public boolean onTouch(View v,MotionEvent event){

                                     int eventPadTouch = event.getAction();
                                     int iX = (int)event.getX();
                                     int iY = (int)event.getY();          
                                     switch (eventPadTouch) {

                                         case MotionEvent.ACTION_DOWN:

                                             if (iX>=0 & iY>=0 & iX<TheBitmap.getWidth() & iY<TheBitmap.getHeight()&TheBitmap.getPixel(iX,iY)!=0) {
                                                 if (TheBitmap.getPixel(iX,iY)!=0) {
                                                     Toast.makeText(getApplicationContext(),"clicked blue",Toast.LENGTH_LONG).show();

                                                 }
                                             }
                                             return true;
                                     }

                                     return false;
                                 }
                             }
Run Code Online (Sandbox Code Playgroud)

android button android-imagebutton

6
推荐指数
1
解决办法
1153
查看次数

如何在Android中以编程方式更改形状的纯色?

我试图改变solid的颜色shape在我的Fragment

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/icon_circle_background">
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            ...>
            <solid android:color="@color/md_cyan_400"/>
        </shape>
    </item>
    <item
        ...
    </item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)

我似乎无法从我的代码中访问它,而且我已经尝试了以下有关堆栈溢出的答案:

以编程方式设置android形状颜色

如何动态改变形状颜色?

在用作背景的 Drawable xml 中在运行时更改形状纯色

这些都不起作用或已经过时了。

我尝试更改颜色的片段:

public class GameFragment extends Fragment {
    private Theme currentTheme;
    private Circle currentCircle;
    private int currentOrganisationId;
    private List<Card> circleCards;
    private List<ImageButton> circleButtons;
    private int viewHeight;
    private int viewWidth;
    private int marginCard;
    private int[] tableStarts;
    private RelativeLayout background;
    private ViewTreeObserver vto;

    public GameFragment() {
        circleCards = new ArrayList<>();
        circleButtons = new …
Run Code Online (Sandbox Code Playgroud)

android shape android-imagebutton

6
推荐指数
1
解决办法
1778
查看次数

如何制作多个页面,我可以在应用程序中使用按钮,并使图像按钮链接到这些页面?

所以这是我的第一个应用程序,我正在尝试编码,需要一些按钮帮助.在寻找答案后,我找不到一个我理解的答案.我希望能够为应用程序创建不同的页面并将imagebuttons链接建立到这些页面.这是我按钮的最基本代码.请尝试解释在哪里放置代码等.提前感谢.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageButton"
        android:background="@drawable/home_button"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:nestedScrollingEnabled="true" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

android button android-imagebutton

5
推荐指数
2
解决办法
3万
查看次数

如何在 ImageButton 中设置 onClick 事件?

我在 android 中创建了一个图像按钮,但是当我点击那个按钮时什么也没有发生。我已经设置了所有属性,但仍然没有发生任何事情。所以你能帮我看看我哪里错了。

xml文件

    <?xml version="1.0" encoding="utf-8"?>
    <AbsoluteLayout
        android:id="@+id/widget39"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        xmlns:android="http://schemas.android.com/apk/res/android">

    <EditText
        android:id="@+id/editText1"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_x="0dp"
        android:layout_y="3dp" />

    <ImageButton
        android:id="@+id/search"
        android:layout_width="40dp"
        android:layout_height="41dp"
        android:layout_x="312dp"
        android:layout_y="10dp"
        android:clickable="true"
        android:onClick="onClick"
        android:background="@drawable/search" />

    />
    </AbsoluteLayout>
Run Code Online (Sandbox Code Playgroud)

搜索.java

public class SearchData extends Activity {
ImageButton search; 

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search_data);
        search =(ImageButton)findViewById(R.id.search);
        search.setOnClickListener(new View.OnClickListener()   {             
               public void onClick(View v)  {               
                try {
                    ConnectService();
                } catch (Exception e) {
                    e.printStackTrace();                    
                }               
               }  
             });
    }
Run Code Online (Sandbox Code Playgroud)

events android onclick listener android-imagebutton

5
推荐指数
1
解决办法
5万
查看次数