我有一个字符串abc~def~ghij~klm~nop~qrstu~vwx~hj.我想将它拆分两次(结果为三个部分):这意味着无论我在哪里得到~符号我需要拆分abc,def第三个只作为单个字符串ghij~klm~nop~qrstu~vwx~hj.
我知道如何在~符号出现的地方分成字符串
String[] parts = stat.split("~");
String part1 = parts[0];
String part2 = parts[1];
String part3 = parts[2];
Run Code Online (Sandbox Code Playgroud)
在这里我只获得part3 ghij,我需要整个字符串保持长~符号.
一位客户要求我制作我的应用程序的版本,使其可以在没有Google Play服务的设备上运行。
有没有办法告诉Android模拟器在不使用GPS的情况下运行该应用程序?
然后,我可以测试代码以确保它可以在客户端设备上运行。
I have some problem with my code, when I need to transfer some data from one Activity to another one.
First Activity (ViewCashflow) and I want transfer some data from ViewCashflow to second Activity (NewTransaction). Here its working well with no error, the data transferred successfully. But, I don't know what's going on when I run the second Activity directly (not from first Activity like before when I transfer the data) I got null pointer exception …
我想更改 aCardView的高度并稍后重新设置。
目前,我不断抬高(所谓的默认值休息标高)作为一个字段值onCreateView的Fragment。稍后当我想重置时,将值设置为setCardElevation.
private CardView cardView;
private float restingElevation;
private float pickedUpState = 50.0f;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment, container, false);
cardView = (CardView) view.findViewById(R.id.table_top);
restingElevation = cardView.getCardElevation(); // keep the default
Log.d("elevation", "resting: " + restingElevation);
return view;
}
private void pickUp() {
cardView.setCardElevation(pickedUpState);
}
private void rest() {
cardView.setCardElevation(restingElevation);
}
Run Code Online (Sandbox Code Playgroud)
但是,我想知道是否有任何直接的方法可以将 aCardView的高程设置为其默认值(静止高程)而不保留onCreateView. Material Design 主题是否有 …
android android-theme android-resources android-styles android-cardview
在活动被杀之前(OnDestroy被叫时),我保存了一些int值SharedPreferences.
但我注意到的是,要保存的值需要大约一秒钟,但应用程序在销毁之前不会等待Activity.
Wait它可以在被杀之前做些什么吗?
这是我的例子:
@Override
public void onDestroy(){
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt("finalXPos", finalX);
editor.putInt("finalYPos", finalY);
editor.commit();
super.onDestroy();
removeView();
}
Run Code Online (Sandbox Code Playgroud)
====================== >>编辑<< ======================
我犯了一个错误,并说这是为了一个,Activity但事实并非如此.我正在调用onDestroy一个服务,不幸的是没有onPause办法覆盖那里......
android android-service android-studio android-sharedpreferences android-ondestroy
为了在我的博客上显示 build.gradle 示例代码,我想使用Prism进行语法突出显示。
但 gradle 并未包含在支持的语言列表中。除了突出显示 gradle 之外,还有其他language-xxxx选择吗?使用language-nginx是一个好的选择吗?
更新于 2022 年 5 月 4 日:
感谢该模块的作者 ABDELKHALEK ZELLAT,您现在可以使用 Gradle。
我的应用程序在运行时崩溃了。我第一次构建和编译它时它有效,但现在不行了。我认为这是由于“DateTimeFormatter”无法在我当前的 api 级别 21 中使用。有解决方法吗?
这是错误:
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/time/format/DateTimeFormatter;
Run Code Online (Sandbox Code Playgroud)
以下是受影响的代码:
@RequiresApi(api = Build.VERSION_CODES.O)
public boolean checkTimeAgainstCurrentTime(String time) throws ParseException {
boolean isTime = false;
DateTimeFormatter parser = DateTimeFormatter.ofPattern("h:mma", Locale.ENGLISH);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
LocalTime theTime = LocalTime.parse(time, parser);
Date time1 = new Date(System.currentTimeMillis());
Date time2 = new SimpleDateFormat("HH:mm:ss").parse(theTime + ":00");
time1.setHours(time2.getHours());
time1.setMinutes(time2.getMinutes());
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Date today = Calendar.getInstance().getTime();
today.setHours(today.getHours()+8);
if (today.after(time1)) {
isTime = true;
}
// If true, means expired.
return isTime;
}
Run Code Online (Sandbox Code Playgroud) 我这里有一个 ShapeableImageView,笔画为 5dp:
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/profile_picture"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="20dp"
android:scaleType="centerCrop"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/profile_toolbar"
app:shapeAppearanceOverlay="@style/circular"
app:strokeColor="@color/dark_blue"
app:strokeWidth="5dp" />
Run Code Online (Sandbox Code Playgroud)
这是结果:
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'我注意到,尽管我在应用程序中使用 ConstraintLayout,但我可以注释掉而不会出现任何错误。
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
// implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.navigation:navigation-fragment:2.3.3'
}
Run Code Online (Sandbox Code Playgroud)
为什么可以呢?com.google.android.material 库是否也包含constraintLayout?
Android SDK 的最新 Beta 版本在 Android 12(模拟器)上运行的每个应用程序上展示了默认启动屏幕,根据要求,我们已经有了自己的启动屏幕。
如果有人研究过它,请告诉我如何禁用/删除它(最好有示例代码)。