标签: android-widget

Android自定义形状按钮

如何在Android中制作自定义形状的可点击视图或按钮?

当我点击时,我想避免触摸空白区域.

在此输入图像描述

请帮忙.谢谢.

android android-widget android-custom-view android-layout onclicklistener

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

如何在Android中为Spinner设置错误消息?

我希望能够像这样调用代码,类似于setError在TextView上设置的方式:

spinner.setError("Error message");
Run Code Online (Sandbox Code Playgroud)

但是,setError仅适用于EditText,而不适用于Spinner.

我想通知用户是否未选择微调器字段.如何在不使用Toast的情况下执行此类通知?

android spinner android-widget

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

设置包含布局的子元素的属性

我有一个main.xml文件描述了我的主要活动的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <include layout="@layout/mylayout" />
    <include layout="@layout/mylayout" />
    <include layout="@layout/mylayout" />
    <include layout="@layout/mylayout" />
    <include layout="@layout/mylayout" />
    <include layout="@layout/mylayout" />

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

及其包含的布局xml文件(mylayout.xml):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mylayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="hello world" />

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

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

我只想在我的主布局中包含5次"mylayout",但是我没有看到"hello world"5次,而是希望TextView包含自定义文本.

有没有办法通过在include元素上设置一些属性来覆盖子TextView的文本?实现这一目标的最佳方法是什么?

android android-widget android-layout

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

vertical DrawerLayout或SlidingPaneLayout

最新的Android支持库引入了DrawerLayout来实现常见的UX模式,您可以向右或向左滑动以显示导航菜单.

我喜欢的是具有相同API 的垂直DrawerLayout,可以从我的布局的顶部/底部向下/向上拉.

从4.2开始,旧的SlidingDrawer已被弃用,我还没有听说过一些实现相同功能的新Widget.

可以DrawerLayout以某种方式扩展以实现垂直滑动UX模式吗?谷歌是否提供了一些不同的小部件来实现它?

例如,谷歌音乐有一些非常类似于我想要实现的方式来拉动播放器.

在此输入图像描述

android android-widget drawerlayout

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

Android中的自定义字体

我已经阅读了一些文章并在谷歌上搜索过,但我没有做到.

我的问题是关于font-face.

在Android中,只有4个属性"android:typeface":Normal,Sans,Serif,Monospace.

那么在我的应用程序中使用"Verdana"需要做些什么呢?

请建议我在Android应用程序中使用此字体的正确方法.

fonts android android-widget

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

Android:在ExpandableListView中隐藏子分隔符

我需要从ExpandableListView中完全删除分隔符.至于父项,它是一个setDividerHeight方法,我可以传递零值.但是对于儿童分隔器没有类似的方法.有没有办法隐藏它?

android android-widget

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

如何在android中使用adb进行出厂重置?

如何使用ADB命令在android中重置工厂?我曾使用adb reboot recovery命令来重置.但第三方应用程序无法以某种方式被清除.这是否正确使用ADB?

实际上,我想通过java代码重置工厂重置android设备.这里可以解决什么问题?

android android-widget android-emulator android-intent

39
推荐指数
4
解决办法
18万
查看次数

在Android中打开/关闭相机手电筒的小工具

我正在开发一个用于打开/关闭手机摄像头的小部件.

我创建了一个可以像切换按钮(开/关)一样工作的小部件.

行为如下所示:当我启用小部件时,有时候led灯仍然亮着.但它不会打开/关闭相机,但它会改变图标.

我无法弄清楚实际问题是什么.

在Activity(火炬之光应用程序)中同样适用.

任何人都可以解释我如何解决我的问题?

我哪里错了?

你可以查看我到目前为止所做的代码

onUpdate 方法

@Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,
            int[] appWidgetIds) {

         //super.onUpdate(context, appWidgetManager, appWidgetIds);

        remoteViews = new RemoteViews( context.getPackageName(), R.layout.widgetlayout);
        watchWidget = new ComponentName( context, FlashLightWidget.class );

        Intent intentClick = new Intent(context,FlashLightWidget.class);
        intentClick.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, ""+appWidgetIds[0]);

        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, appWidgetIds[0],intentClick, 0);
        remoteViews.setOnClickPendingIntent(R.id.myToggleWidget, pendingIntent);
        appWidgetManager.updateAppWidget( watchWidget, remoteViews );
        ctx=context;      
    }
Run Code Online (Sandbox Code Playgroud)

onReceive 方法如下:

@Override

    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub

        remoteViews = new RemoteViews( context.getPackageName(), R.layout.widgetlayout);
        if (intent.getAction()==null) …
Run Code Online (Sandbox Code Playgroud)

android widget android-widget android-camera android-appwidget

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

如何在android上设置等于另一个小部件的宽度

我需要在文本字段下面绘制一条水平线,使得线条的宽度等于文本宽度(而不是整个屏幕的宽度).

在我的应用程序中,我在视图下方有一个textview(水平线).的线视图的宽度应等于TextView的的宽度.我试过android:layout_width ="wrap_content"和"match_parent",但这并没有解决问题.

这是xml编码示例:

         ......
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="28dp"
            android:text="PopUpWindow"
            android:textAppearance="?android:attr/textAppearanceLarge" />


            <View
                android:id="@+id/separator"
                android:layout_width="wrap_content"
                android:layout_height="0.3dp"
                android:layout_below="@+id/textView1"
                android:background="#ffffff" />
             ......
Run Code Online (Sandbox Code Playgroud)

屏幕的图像是:

在此输入图像描述

请帮我.

android android-widget android-layout android-view

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

如何在单个应用程序中使用app小部件创建Android应用程序

我已经完成了一个Android应用程序,它存储了人名和电话号码的日期.

现在我必须为这个应用程序开发一个小部件,用按钮显示今天的(日期,人名和电话号码).

要求:

  1. 使用app和widget的单个应用程序.
  2. 当我点击小部件中的按钮时,它将启动我的应用程序.
  3. 小部件数据应该始终与我的应用程序同步 - 当今天(人5和应用程序添加5个人,然后小部件显示10个人数据)
  4. 我该如何设计这个小部件?任何准则?我必须使用水平ScrollView.

我做了一个简单的小部件演示,但我不知道如何将它与我的应用程序同步.

请分享您的经验,并对我的小部件和应用程序有所了解.

android-widget android-layout android-activity

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