我开始使用NDK在Android上工作,我想检查设备在我的c代码上运行的Android API级别.我怎样才能做到这一点?
起初我以为我可以使用__ANDROID_API__/android/api-level.h下的定义但这是一个错误的假设.
**注意:我不是问如何通过java检查API级别.
我想用模式微调器而不是日历显示DatePickerDialog.在我的styles.xml中,我尝试使用此属性,但它说我应该使用的最小SDK版本是API 21.
<item name="android:datePickerMode">spinner</item>
Run Code Online (Sandbox Code Playgroud)
我使用的是最低版本的SDK 18.如果API低于API 21,如何将默认日期选择器模式设置为微调器?
这是我日期选择器的Java代码:
public class MyDatePicker extends DialogFragment implements DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
DatePickerDialog datePickerDialog = new DatePickerDialog(getContext(), R.style.MyTheme, this, 0, 0, 0 );
return datePickerDialog;
}
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
}
Run Code Online (Sandbox Code Playgroud)
}
谢谢!
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){...do something..}
无法找到 N。如何检查高于 android N 的版本
我试图在我的代码中创建一个条件来比较 Android 版本。类似于;
if(version < 2.2)
{// TODO }
else
{// TODO }
Run Code Online (Sandbox Code Playgroud)
有人可以让我知道如何做到这一点吗?
我有一个自定义alertdialog,膨胀这个自定义布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/infoLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:theme="@style/AppTheme" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:weightSum="2" >
<TextView
android:id="@+id/infoVersionTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right|center"
android:text="@string/infoVersion"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/infoVersionTitleValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<TextView
android:id="@+id/infoDetailText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout1"
android:padding="10dp" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我在我的清单文件中有这个:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
........
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
Run Code Online (Sandbox Code Playgroud)
我已经通过这种方式定义了style.xml:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="android:Theme.Light"></style>
</resources>
Run Code Online (Sandbox Code Playgroud)
style.xml v11定义如下:
<resources>
<style name="AppTheme" parent="android:Theme.Light"></style>
</resources>
Run Code Online (Sandbox Code Playgroud)
而style.xml v14的定义如下:
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar" />
</resources>
Run Code Online (Sandbox Code Playgroud)
在4.0.3设备上运行时,它显示如下:

并在2.3.3设备上运行它显示如下:

在2.3.3设备上,文本几乎不可读,我想显示白色背景(包括标题栏) …
我想要一个活动类,例如ActivityLegacy,用于比级别 x 更旧的 API 级别和一个活动类,例如ActivityNew用于较新的设备。
我有可能在运行时选择正确的实现并加载它吗?我不想开始一个新的意图。
我在运行应用程序时遇到此活动崩溃.这不是由于appcompat,因为您可以在堆栈跟踪中看到.这是本机android ListView类,在运行应用程序时找不到该方法.
相同的应用程序在其他设备上正常运行.minSdkVersion = 13 target = 23 max = 23,崩溃的当前设备是API 17.
FATAL EXCEPTION: main
java.lang.NoSuchMethodError: android.widget.ListView.setElevation
at com.example.saloni.laughgurumarketingapp.ContentDetails.getValues(ContentDetails.java: 392)
at com.example.saloni.laughgurumarketingapp.ContentDetails.onCreate(ContentDetails.java: 298)
at android.app.Activity.performCreate(Activity.java: 5122)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java: 1081)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java: 2270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: 2358)
at android.app.ActivityThread.access$600(ActivityThread.java: 156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java: 1340)
at android.os.Handler.dispatchMessage(Handler.java: 99)
at android.os.Looper.loop(Looper.java: 153)
at android.app.ActivityThread.main(ActivityThread.java: 5297)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java: 511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 600)
at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
在代码中,它只是一个设置的提升方法,正如您在跟踪中看到的那样,它正在崩溃.同样,它上次使用其中一个TextView类方法时崩溃了.为什么会这样?
如何以编程方式获取当前的android deveice版本(1.5,1.6,2.0等).即我已经在ANdroid 2.2设备中安装了我的apk ..我需要获取设备版本(我的应用程序当前正在运行的android模拟器版本)
我需要检查我的手机的Android版本,如果版本低于4.0.0我应该执行以下代码,否则它不应该执行.我怎么能这样做?我用这一行来获得Android版本.
String androidOS = Build.VERSION.RELEASE;
Run Code Online (Sandbox Code Playgroud)
我怎么能检查是否低于4.0.0.建议我一个解决方案.