我知道我可以忽略属性中的Lint规则 tools:ignore
我的困难在于我想忽略几条规则.就我而言,对于Google分析ga_trackingId,我想忽略TypographyDashes和MissingTranslation
我试过没有成功
<resources tools:ignore="TypographyDashes|MissingTranslation" xmlns:tools="https://schemas.android.com/tools" >
Run Code Online (Sandbox Code Playgroud)
和
<resources tools:ignore="TypographyDashes,MissingTranslation" xmlns:tools="https://schemas.android.com/tools" >
Run Code Online (Sandbox Code Playgroud)
和
<resources tools:ignore="TypographyDashes MissingTranslation" xmlns:tools="https://schemas.android.com/tools" >
Run Code Online (Sandbox Code Playgroud)
我现在没有想法.如何指定多个值tools:ignore?
我有4种不同的设备:
我想知道我的设备的最小宽度(sw)为它做一个支撑布局.
我想创建一个像"layout-sw600dp"这样的资源文件夹,但我不知道最小宽度(sw)的值.
我尝试使用以下代码打印sw:
DisplayMetrics metrics = getResources().getDisplayMetrics();
Log.i("Density", ""+metrics.densityDpi);
Run Code Online (Sandbox Code Playgroud)
但我不知道这是否是正确的价值.
如何找到最小宽度(sw)?
我有我的xml字符串文件,如下所示:
<string name="text1">ben & angie</string>
Run Code Online (Sandbox Code Playgroud)
但它说我有一个未转义的&.怎么逃避呢?
我在Visual Studio 2017上开发时遇到了一个奇怪的错误,我已经能够忽略一段时间,但现在开始真的让我感到烦恼.
我将此问题称为错误而不是错误,因为我仍然可以在Visual Studio中构建我的项目并将它们部署到我的开发设备,而不会出现构建输出中的错误或警告.这似乎可以忽略一点,但随着时间的推移它已成为一个问题,因为我的intellisense用红色强调它作为一个错误
每次我引用Resource类的属性.正如你可能猜到的那样,我引用了很多这个类,Visual Studio编辑器最终变得混乱了这些"错误",它们(a)阻碍了我在代码中发现实际错误的能力,并且(b)让我无法理解......
.
该.csproj的配置文件包含的标签:
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
<AndroidResgenClass>Resource</AndroidResgenClass>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v7.1</TargetFrameworkVersion>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
Run Code Online (Sandbox Code Playgroud)我正在按照此解决方案在我的字符串资源文件中使用enetities:
是否可以直接在Android资源XML文件中进行字符串替换?
我在资源树中使用外部文件:/res/raw/entities.dtd,其内容:
<!ENTITY ent_devicename "MyDeviceName">
Run Code Online (Sandbox Code Playgroud)
在string.xml资源文件中:
<!DOCTYPE resources [
<!ENTITY % ent_devicename SYSTEM "../raw/entities.dtd">
%ent_devicename;
]>
<resources>
<string name="name">The name is &ent_devicename;</string>
</resources>
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
实体"ent_devicename"已被引用,但未被声明.
如您所见,Android Studio可识别外部实体文件:
和实体:
有人能提供一个正确的例子来使事情有效吗?我的意思是一个完全可编译的Android Studio项目,在单独的文件中包含实体声明.
更新 好的,如果你更加关注这个w3schools链接:
https://www.w3schools.com/xml/xml_dtd_entities.asp
你看到了解决方案:
外部entities.dtd文件包含
<!ENTITY ent_devicename "MyDeviceName">
Run Code Online (Sandbox Code Playgroud)
那么新的字符串资源资源:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE resources [
<!ENTITY ent_devicename SYSTEM "../raw/entities.dtd">
]>
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="Typos">
<string name="ent_devicenamxxe2">&ent_devicename;</string>
Run Code Online (Sandbox Code Playgroud)
我改变了<!ENTITY % ent_devicename对<!ENTITY ent_devicename(不再%)我删除%ent_devicename;
现在它编译但是生成的APK似乎忽略了实体值(使用空字符串).所以问题没有解决!
让我知道!
xml dtd android-resources android-studio android-gradle-plugin
所以我环顾四周,发现它android.R.styleable不再是SDK的一部分,即使它仍然在这里记录.
如果清楚地记录了备选方案的内容,那就不会成为问题.例如,AOSP日历应用程序仍在使用android.R.styleable
// Get the dim amount from the theme
TypedArray a = obtainStyledAttributes(com.android.internal.R.styleable.Theme);
lp.dimAmount = a.getFloat(android.R.styleable.Theme_backgroundDimAmount, 0.5f);
a.recycle();
Run Code Online (Sandbox Code Playgroud)
那么如果backgroundDimAmount没有得到它int[],怎么会得到android.R.styleable.Theme?
obtainStyledAttributes(int [])为了使其与SDK一起使用,我需要注意什么?
我是Android开发的新手,我一直在玩它.我试图创建一个程序,该程序具有类似数据库的小型永不变化数据集合.在C#中,我目前最好的语言,我使用自定义类的列表并将其序列化为xml文件,然后在运行时将其读入我的应用程序.我在Android中找到了/ xml资源文件夹,但我不确定如何去做我想象的事情.这样做最好的方法是什么?
数据永远不需要改变.例:
Blob | A | B
----------------
Blob 1 | 23 | 42
Blob 2 | 34 | 21
Run Code Online (Sandbox Code Playgroud)
我知道它的布局就像一张桌子,但使用数据库对我来说并没有多大意义,因为数据永远不会改变,我需要一种方法来存储它,无论如何最初填充数据库.
所以基本上我正在寻找一种在我的应用程序中存储有些复杂的静态数据的方法.有任何想法吗?
编辑:我也看到了/ raw文件夹.所以我可以将东西存储在/ res/raw或/ res/xml中.但我不确定存储/解析数据的最佳方法是什么......
xml android android-pullparser android-parser android-resources
两个活动都在同一个包中
第二个活动使用第二个布局文件
setContentView(R.layout.main2);
Run Code Online (Sandbox Code Playgroud)
Second_Activity中此行的错误.
EditText text1 = (EditText) findViewById(R.id.EditText03);
Run Code Online (Sandbox Code Playgroud)
这是Second_Activity的布局文件.
<?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" >
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Answer Is : " >
</TextView>
<EditText
android:id="@+id/EditText03"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</EditText>
</LinearLayout>
<Button
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="Calling an intent" >
</Button>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
以下是LogCat窗口中的错误
08-01 19:32:20.340: WARN/ResourceType(8875): No package identifier when getting value for resource number 0x00000005
08-01 19:32:20.390: ERROR/AndroidRuntime(8875): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x5
Run Code Online (Sandbox Code Playgroud)
mail.xml
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content" …Run Code Online (Sandbox Code Playgroud) 我通常将尺寸存储在dimen.xml文件中.但是,IntelliJ IDEA的intellisense将维度放入文件中dimens.xml.
现在,如果我将维度放入文件中dimens.xml,Eclipse将如何处理?
我看到docs允许使用这两个文件.哪一个应该被使用,如果该项目将通过使用两个 Eclipse和IDEA用户?
如何防止Android"构建过程"优化.png图像?
我有一个包含以下res目录的Android项目:
- /res/
- /res/drawable
- /res/drawable-hdpi
- /res/drawable-hdpi-v5
- /res/drawable-ldpi
- /res/drawable-ldpi-v5
- /res/drawable-mdpi
- /res/drawable-mdpi-v5
Run Code Online (Sandbox Code Playgroud)
这些目录包含许多.png文件.我使用PNGOUTWin优化PNG尺寸,整体尺寸减少了20%以上.当我构建.apk文件时,图像由构建过程"优化",整体大小现在比初始大小高10%,或者比我的/ PNGOUTWin优化大小高30%.
我的目标是减小.apk大小,即使它会影响最终性能,内存要求等.如何防止"构建过程"优化.png图像?
我的目标是Android 2.2及更高版本.
PS:我目前正在从Eclipse构建我的Android项目,但我稍后会切换到自动构建(Ant?).
关于JPG图像的注意事项: JPG不起作用,因为它们没有透明度.