标签: android-button

如何将样式应用于Android中的所有ImageButtons?

我的应用程序中有以下样式.

  <style name="BtnPressed">
      <item name="android:background">@drawable/btn_default</item>
  </style>
Run Code Online (Sandbox Code Playgroud)

现在我想将它应用于ImageButtons我的应用程序中的所有内容.我试图使用这个问题中提到的解决方案,但它没有用.我正在使用API​​-7.

android android-imageview android-button

3
推荐指数
1
解决办法
4949
查看次数

在GridLayout中对齐按钮

我的布局代码及其图形表示是:

在此输入图像描述

这只是一个例子,我Buttons在我的应用程序中有大约30 个GridLayout.我希望我Buttons在网格中填充整个单元格,网格的列应该是均匀的宽度/高度.

我似乎无法完成它,欢迎任何帮助.

android gravity grid-layout android-button

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

Android自定义按钮通用点击处理程序

我正在尝试实现一个自定义按钮,它允许我在单击按钮时执行一组标准操作(例如编写日志),并执行特定于每个按钮实例的指定单击侦听器.可能吗?

非常感谢

android buttonclick android-custom-view android-button

3
推荐指数
1
解决办法
2834
查看次数

长时间点击事件并在Android中长按

我想要两个单独的事件长按单击向下和长按.我怎样才能在Android中执行此操作?

我试过的内容如下

public class FfwRewButton extends ImageButton {

    public interface ButtonListener {

        void OnLongClickDown(View v);

        void OnLongClickUp(View v);
    }

    private ButtonListener mListener;

    private boolean mLongClicked = false;

    public FfwRewButton(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        setFocusable(true);
        setLongClickable(true);
    }

    public FfwRewButton(Context context) {
        this(context, null);
    }

    public FfwRewButton(Context context, AttributeSet attrs) {
        this(context, attrs, android.R.attr.imageButtonStyle);
    }

    @Override
    public boolean onKeyLongPress(int keyCode, KeyEvent event) {
        Log.d("my listener", "long press");
        mLongClicked = true;
        mListener.OnLongClickDown(this);
        return super.onKeyLongPress(keyCode, event);
    }

    @Override
    public …
Run Code Online (Sandbox Code Playgroud)

android android-button

3
推荐指数
1
解决办法
3577
查看次数

使用按钮显示/隐藏文本

我试图通过button单击显示文本。

这是我的onClick代码:

public class Uteliv extends Activity {

    public void onCrate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_uteliv);

        TextView tidiTekst = (TextView) findViewById(R.id.tidiTekst);
        tidiTekst.setVisibility(View.GONE);

        Button tidiKnapp= (Button) findViewById(R.id.tidiKnapp);
        tidiKnapp.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            tidiTekst.setVisibility(View.VISIBLE);

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

怎么了?在手机上测试时,我只会得到空白页。

android textview android-button

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

以百分比设置按钮的大小

请查看以下代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".HomeScreen" >

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:stretchColumns="*"
        android:layout_alignParentTop="true" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <Button
                android:id="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />

            <Button
                android:id="@+id/button2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />

            <Button
                android:id="@+id/button3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />

        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <Button
                android:id="@+id/button4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />

            <Button
                android:id="@+id/button5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />

            <Button
                android:id="@+id/button6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />

        </TableRow>

        <TableRow
            android:id="@+id/tableRow3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <Button
                android:id="@+id/button7"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />

            <Button
                android:id="@+id/button8"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" /> …
Run Code Online (Sandbox Code Playgroud)

java eclipse user-interface android android-button

3
推荐指数
1
解决办法
2492
查看次数

在Google地图Android上显示一个按钮

嗨,我想在谷歌地图上显示一个按钮,有人可以告诉我如何实现这一点,因为我尝试了不同的位置,我的按钮显示在地图后面.

到目前为止这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/BlanchedAlmond" >

<Button
    android:id="@+id/startActivityButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal|center_vertical"   
    android:onClick="startActivity"
    android:text="@string/start_activity" 
    android:layout_alignParentBottom="true"  />

   <fragment        
    android:id="@+id/map"      
    android:name="com.google.android.gms.maps.MapFragment"        
    android:layout_width="wrap_content"        
    android:layout_height="wrap_content"
    android:layout_above="@id/startActivityButton"    
    /> 

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

android google-maps-api-2 android-button

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

Lollipop在我的应用程序中利用Buttons的文本

我在申请时遇到了一个奇怪的问题.当我在真实设备(使用Android 4.4.4)上测试它时,我所有的按钮文本字段看起来我想要的(小写字母).但是当我在模拟器(Android 5.0.1)上启动我的应用程序时,所有Button文本字段都是大写的.这种行为的原因是什么?我的应用程序中的一些示例按钮:

示例按钮1:

    <Button
        android:id="@+id/button5"
        android:layout_width="match_parent"
        style="?android:attr/borderlessButtonStyle"
        android:layout_height="wrap_content"
        android:text="@string/finish"
        android:textColor="#FFFFFF"
        android:textSize="30sp"
     />
Run Code Online (Sandbox Code Playgroud)

示例按钮2:

    <Button
        android:id="@+id/button3"
        android:layout_width="0dp"
        style="?android:attr/borderlessButtonStyle"
        android:layout_height="wrap_content"
        android:text="@string/flower"
        android:textColor="#FFFFFF"
        android:textSize="30sp"
        android:drawableLeft="@drawable/flower"
        android:layout_weight=".75"
        />
Run Code Online (Sandbox Code Playgroud)

这个问题的解决方案是什么?我希望我的应用程序在所有sw版本上看起来都一样.

android android-emulator android-layout android-button android-5.0-lollipop

3
推荐指数
1
解决办法
6472
查看次数

Android MotionEvent仅检测ACTION_MOVE

根据android MotionEvent文档:在按下手势(ACTION_DOWN和之间ACTION_UP)发生了更改。运动包含最近的点以及自上次下移或移动事件以来的任何中间点。

ACTION_MOVE Android文档

所以,当我应用setOnTouchListene上我的看法是完美的作品,它给我ACTION_DOWNACTION_UPACTION_MOVE

但是我的问题是我只想忽略ACTION_DOWN之前发生的事件ACTION_MOVE。因为ACTION_MOVE事件仅ACTION_DOWN根据其文档在事件之后发生。

我的编码:

      button.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                switch (event.getAction() & MotionEvent.ACTION_MASK) {
                    case MotionEvent.ACTION_DOWN:
                        Log.e("Mouse: ", "Click");
                        break;
                    case MotionEvent.ACTION_MOVE:
                        Log.e("Mouse: ", "Move");
                        break;
                }

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

因此,有什么原因可以忽略ACTION_DOWN事件。因为用户只想移动就不想单击,而且ACTION_MOVE还发生ACTION_DOWN在它自己执行之前。

谢谢...

android motion-detection multi-touch android-button motionevent

3
推荐指数
1
解决办法
1441
查看次数

setBackgroundTintList用于以编程方式使用十六进制值/ ColorDrawable的按钮

我试图以编程方式设置按钮的背景色,而不是像此处那样设置为颜色资源,而是设置为十六进制值。目前,我已经将十六进制值转换为ColorDrawable,但不知道如何使用该.setBackgroundTintList()方法通过按钮的方法设置背景色。请注意,这是在Fragment中完成的,上下文存储在名为的全局变量中mContext

ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#FFFFFF"));
Run Code Online (Sandbox Code Playgroud)

android android-button colordrawable

3
推荐指数
1
解决办法
1399
查看次数