小编jbw*_*bww的帖子

从列表首选项中获取整数或索引值

我在共享首选项中创建列表,当调用onPreferenceChanged()方法时,我想提取列表中项目的索引或某些情况下的整数值.我正在尝试构建xml数据,如下所示:

在数组中:

<string-array name="BackgroundChoices">
  <item>Dark Background</item>
  <item>Light Background</item> 
</string-array>
<array name="BackgroundValues">
  <item>1</item>
  <item>0</item> 
</array>
<string-array name="SpeedChoices">
  <item>Slow</item>
  <item>Medium</item>
  <item>Fast</item>
</string-array>    
<array name="SpeedValues">
  <item>1</item>
  <item>4</item>
  <item>16</item>
</array>
Run Code Online (Sandbox Code Playgroud)

在首选项xml文件中:

<PreferenceScreen android:key="Settings"  
   xmlns:android="http://schemas.android.com/apk/res/android"  
   android:title="Settings">

<ListPreference
        android:key="keyBackground"
        android:entries="@array/BackgroundChoices"
        android:summary="Select a light or dark background." 
        android:title="Light or Dark Background"  
        android:positiveButtonText="Okay"   
        android:entryValues="@array/BackgroundValues"/>
<ListPreference 
        android:key="keySpeed" 
        android:entries="@array/SpeedChoices" 
        android:summary="Select animation speed."
        android:title="Speed" android:entryValues="@array/SpeedValues"/>
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)

所以我的xml不起作用.我知道如何使用字符串数组而不是数组来表示值.我可以提取值字符串并从中得到我想要的但我宁愿(如果可能的话)能够得到值为int,booleans或enums的列表.这样做的习惯方法是什么?

提前致谢,

松鸦

android sharedpreferences

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

使用主题为首选项屏幕

我希望更改我正在处理的应用程序首选项屏幕的外观.在某些手机上,首选项是非常半透明的,并且很难阅读首选项方案,因此我将更改它的视觉效果.

我的问题是如何将主题应用于偏好方案?或者如果不这样做,我如何更改显示各种首选项的文本颜色.

在我当前的版本中,我的首选项布局xml文件以:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffa0a0a0">
Run Code Online (Sandbox Code Playgroud)

这种背景颜色给了我一个可接受的灰色,但我更喜欢使用一个主题.

我尝试在首选项xml和首选项布局xml中应用几个不同的主题,但这些都没有显示任何效果.我还尝试为各个首选项和布局设置andoid:textColor,但没有效果.

那么如何修改首选项方案的视觉效果(最好是使用主题)?

提前致谢,

松鸦

android themes preferences

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

更好的方法只调试断言代码

我正在编写我的第一个Android应用程序,我很自由地使用junit.framework.Assert中的asserts()

我想找到一种方法来确保断言只被编译到调试版本中,而不是发布版本中.

我知道如何从清单查询android:debuggable属性,所以我可以创建一个变量,并在以下fashon中完成此操作:

static final boolean mDebug = ...

if(mDebug)Assert.assertNotNull(view);

有一个更好的方法吗?即我不想在每个断言中使用if().

谢谢

android

8
推荐指数
2
解决办法
7895
查看次数

无法获取设置按钮以显示动态壁纸

我想为我创建的动态壁纸添加设置.我遗漏了一些关于SharedPreferences如何工作的基本信息.代码和XML基于多维数据集动态壁纸示例,我无法弄清楚我做错了什么.我的问题是当我从列表中选择我的动态壁纸时,没有"设置"按钮出现.仅显示"设置壁纸"按钮.我怀疑我搞砸了XML中的一些东西.

这是一个非常简单的动态壁纸,我只是为了愚弄设置.它只是将背景设置为蓝色或绿色(并且该部分有效).

我认为相关的代码和xml如下:

AndroidManifest.xml中

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.android.BGWallpaper"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="7" />
    <uses-feature android:name="android.software.live_wallpaper" />

    <application
        android:icon="@drawable/icon" android:label="@string/AppName">

        <service
            android:icon="@drawable/icon"
            android:label="@string/AppName"
            android:name="com.android.BGWallpaper.BlueGreen"
            android:permission="android.permission.BIND_WALLPAPER" android:debuggable="false">
            <intent-filter android:priority="1">
                <action android:name="android.service.wallpaper.WallpaperService" />
            </intent-filter>
            <meta-data android:name="android.service.wallpaper" android:resource="@xml/bg" />
        </service>
        <activity
            android:label="BGSettings"
            android:name="com.android.BGWallpaper.BGPrefs"
            android:theme="@android:style/Theme.Light.WallpaperSettings"
            android:exported="true">
        </activity>
    </application>
</manifest>
Run Code Online (Sandbox Code Playgroud)

的preferences.xml:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
        android:title="Title Preference"
        android:key="BGSettings">
    <ListPreference
            android:key="background"
            android:title="Background Title"
            android:summary="Background Summary"
            android:entries="@array/BackgroundChoices"
            android:entryValues="@array/BackgroundChoices" />
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)

bg.xml

<?xml version="1.0" encoding="utf-8"?>
<wallpaper 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:thumbnail="@drawable/icon"/>
Run Code Online (Sandbox Code Playgroud)

BlueGreen.java(壁纸服务)

public class BlueGreen extends WallpaperService 
{
    public …
Run Code Online (Sandbox Code Playgroud)

android android-preferences

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

NSLog导入和库

我不敢相信我发现这个有多麻烦:

我想用 NSLog()

我该怎么做#import以及我链接到哪个库?

提前致谢,

松鸦

iphone nslog

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

以编程方式设置AdMob id String

我正在使用几个使用常见XML界面元素的应用程序.其中一个元素加载AdMob.我可以复制每个项目中的元素,并ID为复制XML文件中的每个应用程序添加唯一,但我想知道是否有一些方法以编程方式设置I应用程序中的D字符串,同时保持XML并且不必在每个项目中复制它.

类似于:

    setContentView(R.layout.main);
    AdView aView = (AdView)findViewById(R.id.admob);
    aView.<method goes here that sets ads:adUnitId>
Run Code Online (Sandbox Code Playgroud)

我知道,而不是实例AdMobXML,我能做到这一点编程,或者说我可以复制main.xml到每一个项目和修改ID在那儿,而不是使用一个在我的图书馆.但是我会更喜欢一个类似于我上面的示例代码的解决方案,它允许我保留AdMob代码main.xml并且不会让我main.xml在更改时在n个位置更新.

我无法找到附带的可交付成果的类引用或完整描述AdMob,并且自动完成不会向我显示任何看似符合此需求的方法.如果有人会把我指向一个对AdMob课程有很好描述的地方,那将是一个很大的帮助.

xml android admob

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

将UIImage保存为其他名称

我正在编写一个应用程序,让用户从选择中选择一张照片.然后我想将照片保存到他们的照片卷到一个特定的名称.即我总是希望将卷中的照片命名为相同的东西,并覆盖以前的选择.

    UIImage* image = [UIImage imageNamed:[ImageNames objectAtIndex:self.miImage]];

    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
Run Code Online (Sandbox Code Playgroud)

无论如何,我找不到制作图像的副本并为其指定新名称,或为UIImageWriteToSavedPhotosAlbum()指定目标名称.

有没有办法做到这一点?

提前致谢,

松鸦

iphone objective-c uiimage

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

将Button/ListView放在布局XML中的相对布局下的问题

以下是我正在处理的内容的布局XML.它应该在显示屏顶部显示和编辑字段和一些按钮,其中ListView填满其余部分.但是只显示RelativeLayout中嵌入的项目.以下项目不显示.我不确定我在布局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" >
<RelativeLayout
    android:orientation="vertical" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:padding="10px">

    <TextView android:id="@+id/tidName" 
              android:layout_width="wrap_content" 
              android:layout_height="wrap_content" 
              android:gravity="center_horizontal"
              android:text="Enter Name:" />

    <EditText android:id="@+id/eidName" 
              android:layout_width="fill_parent" 
              android:layout_height="wrap_content" 
              android:background="@android:drawable/editbox_background"
              android:layout_below="@id/tidName" />

    <Button android:id="@+id/bidShow" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:layout_below="@id/tidName"
            android:layout_alignParentRight="true"
            android:layout_marginLeft="10px"
            android:text="Show Search Results" />

    <Button android:id="@+id/bidUseDefault"
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:layout_below="@id/tidName"
            android:layout_alignParentLeft="true"
            android:layout_marginRight="10px"
            android:text="Use Default" />

</RelativeLayout>
<Button 
            android:layout_below="@id/ridMain"
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:text="Refresh" />
<ListView android:id="@+id/lidResults"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

提前致谢,

xml layout android listview

0
推荐指数
1
解决办法
1513
查看次数