我想在棒棒糖设备中显示较旧的时间选择器(如前棒棒糖设备时间选择器).这可能吗?
我正在尝试使用 Android 中的 SharedElements 和 Content Transitions。我试图结合 Content Transitions 和 Shared Elements 并创建一个特定的动画,但是我遇到了一个问题。在共享元素 (ImageView) 上的过渡结束后,我使用内容过渡将文本视图动画化到使用幻灯片过渡的位置。然而,当 textViews 从底部滑动到它们在图像视图顶部的位置时,文本会在 ImageView(共享元素)下方,然后才出现在 ImageView 的顶部。有没有办法做到这一点?

我在这里分享一个简短的代码,其中包含一些解释这一点的屏幕截图:
Activity_A.java
package com.example.mehulp.sharedelementsviewheirarchy;
import android.app.Activity;
import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
public class Activity_a extends Activity {
ImageView imageView_a;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity_a);
imageView_a = (ImageView) findViewById(R.id.imgView_a);
imageView_a.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imageClickListener();
}
});
}
private void imageClickListener() {
Intent intent = new Intent(Activity_a.this, Activity_b.class);
startActivity(intent, …Run Code Online (Sandbox Code Playgroud) android android-transitions shared-element-transition android-5.1.1-lollipop
我嵌套了 LinearLayouts,其中一个在 ScrollView 内有一组垂直的 EditText。问题每次我单击其中一个 EditText 和 Android 中的键盘时,这些 EditText 的一半都会消失,如果我在第一个编辑文本中写入,我什至看不到它或滚动到其中。
我在 Stackoverflow 中尝试了不同的解决方案,例如添加android:windowSoftInputMode="adjustPan|adjustResize",但没有成功。
这是我的MainActivity.xml
LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MainActivity">
<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginTop="10dp"
android:src="@drawable/clac"
android:scaleType="centerCrop"
android:layout_gravity="center"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center"
android:layout_marginTop="16dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Letter Grade"
android:textSize="15sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Credit Hours"
android:textSize="15sp"
android:layout_marginLeft="60dp"
/>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:focusable="true"
android:focusableInTouchMode="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:id="@+id/inputform">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:layout_marginTop="10dp" …Run Code Online (Sandbox Code Playgroud) android scrollview android-layout android-studio android-5.1.1-lollipop
我正在编写应该在Android L和M上运行的应用程序
您可能知道,对于Android M,需要在代码中询问写入\从外部存储(sdcard)读取的权限,如下所示:
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)==
PackageManager.PERMISSION_GRANTED)
requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0);
Run Code Online (Sandbox Code Playgroud)
但是,我遇到了一个问题,因为调用checkSelfPermission需要API级别23(而不是22,因为我需要Lollipop支持).
我试图添加,@TargetApi(Build.VERSION_CODES.MNC)但我面临另一个问题 -"Cannot resolved symbol MNC"
那么问题是,我如何编写代码来保存sdcard中的文件,Lollipop和Marshmallow?
编辑:项目结构设置:
编译Sdk版本:API 23:Android 5.X(MNC
Min Sdk版本:API 22:Android 5.1(Lollipop)
Target Sdk版本:API 23:Android 5.X(MNC)
谢谢
我正在删除电话号码任务的特定短信.当我在motog或Android 5.0版的手机上测试时.我无法删除特定号码的短信.我的代码片段如下.
public void deleteSMS(Context context,String number) {
try {
Log.d("","Deleting SMS from inbox");
Uri uriSms = Uri.parse("content://sms/inbox");
Cursor c = context.getContentResolver().query(uriSms,
new String[] { "_id", "thread_id", "address",
"person", "date", "body" }, "address = '"+number+"'", null, null);
if (c != null && c.moveToFirst()) {
do {
long id = c.getLong(0);
long threadId = c.getLong(1);
String address = c.getString(2);
String body = c.getString(5);
Toast.makeText(getApplicationContext(),"SMS with id: " + threadId +" Number:- " +address,Toast.LENGTH_LONG).show();
Log.d("", "SMS with id: " + threadId +" …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个像Lollipop一样的警报对话框,一切都很顺利,但我在一个部分陷入了EditText的情况
我想要一个带有下划线和边距的EditText 左右 20dp.对于下划线我尝试了setBackground(),并且它工作正常.
但是有一个问题是setBackground()不能在低于16的API级别工作.
对于setMargin,我试过了
final EditText input = new EditText(MainActivity.this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(30,0,30,0);
input.setLayoutParams(lp);
input.setGravity(View.TEXT_ALIGNMENT_GRAVITY);
input.setBackground(getResources().getDrawable(R.drawable.edit_text_line));
builder.setView(input);
Run Code Online (Sandbox Code Playgroud)
但是使用完整父宽度编辑文本.
完整代码
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Message");
builder.setMessage("Do you want to\n"+""+"exit from app");
final EditText input = new EditText(MainActivity.this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(30,0,30,0);
input.setLayoutParams(lp);
input.setGravity(View.TEXT_ALIGNMENT_GRAVITY);
input.setBackground(getResources().getDrawable(R.drawable.edit_text_line)); //call reequires api 16 and above
builder.setView(input);
builder.setNegativeButton("No", new DialogInterface.OnClickListener() …Run Code Online (Sandbox Code Playgroud) android android-edittext android-alertdialog android-5.1.1-lollipop
我正在开发Android Tablet应用程序,我正在检查名为"Home"的Activity中的Internet连接.我已经在Android版本4.2(平板电脑),4.4(平板电脑),5.0(手机),5.0.2(手机)中测试了应用程序,应用程序运行正常.
问题: 当我在Android 5.1.1(平板电脑)中测试应用程序时,应用程序被强制关闭.它在日志中显示以下错误.
日志:
2015-07-27 05:36:19.312 ERROR: AndroidRuntime : java.lang.RuntimeException: Unable to start activity ComponentInfo{com.freestyle/com.freestyle.Home}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.net.NetworkInfo.isConnectedOrConnecting()' on a null object reference
2015-07-27 05:36:19.312 ERROR: AndroidRuntime : at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
2015-07-27 05:36:19.312 ERROR: AndroidRuntime : at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
2015-07-27 05:36:19.312 ERROR: AndroidRuntime : at android.app.ActivityThread.access$800(ActivityThread.java:151)
2015-07-27 05:36:19.312 ERROR: AndroidRuntime : at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
2015-07-27 05:36:19.312 ERROR: AndroidRuntime : at android.os.Handler.dispatchMessage(Handler.java:102)
2015-07-27 05:36:19.312 ERROR: AndroidRuntime : at android.os.Looper.loop(Looper.java:135)
2015-07-27 05:36:19.312 ERROR: AndroidRuntime : at android.app.ActivityThread.main(ActivityThread.java:5254)
2015-07-27 …Run Code Online (Sandbox Code Playgroud) 我在RecyclerView中使用CardView.在阅读了很多内容之后,我最终只在Android 5.1.1上使用了"NOT WORKING"代码.在Android版本之前,它的工作很好.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#11ffffff"
android:orientation="vertical"
android:paddingBottom="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#11ffffff">
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@color/primary_bg_light"
card_view:cardCornerRadius="2dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/primary_bg_light">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:paddingBottom="15dp"
android:paddingLeft="15dp"
android:textColor="@color/background_floating_material_light"
android:textSize="24sp"
android:textStyle="bold" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我确实尝试使用代码设置高程,但结果相同.
在获得带有 Lollipop 的 Android 设备后,我注意到我们为 Kitkat(和以前的版本)工作的 AudioTrack 代码完全停止工作,完全相同的代码适用于 Lollipop 之前的设备,所以我想知道我在做什么新版本做错了。AudioTrack以下是(由属性引用mTrack)的初始化方式:
protected void onCreate(Bundle savedInstanceState) {
int bufferSize = AudioTrack.getMinBufferSize(AUDIO_SAMPLE_RATE, AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT);
mTrack = new AudioTrack(AudioManager.STREAM_MUSIC, AUDIO_SAMPLE_RATE,
AudioFormat.CHANNEL_CONFIGURATION_STEREO,
AudioFormat.ENCODING_PCM_16BIT, bufferSize,
AudioTrack.MODE_STREAM);
}
Run Code Online (Sandbox Code Playgroud)
以下是缓冲区的填充方式:
public void onPlayAudio(byte[] audioBuffer) {
if (mTrack.getPlayState() != AudioTrack.PLAYSTATE_PLAYING) {
mTrack.play();
}
if (audioBuffer != null) {
mTrack.write(audioBuffer, 0, audioBuffer.length);
}
}
Run Code Online (Sandbox Code Playgroud)
同样,这在 Lollipop 之前的设备上运行良好。Logcat 上没有错误,一切似乎都正常,但声音不出来(是的,我检查了音量,它一直开到最大)。所以我想知道我是否缺少更新或者我做错了什么。
我注意到AudioFormat.CHANNEL_CONFIGURATION_STEREO已被弃用,但尝试建议AudioFormat.CHANNEL_OUT_STEREO似乎并不能解决问题。
任何帮助将不胜感激。
android audiotrack android-5.0-lollipop android-5.1.1-lollipop
如何检测用户在我的应用程序中启动了哪个应用程序,即即使我的应用程序未在前台或后台运行,当用户启动 Whatsapp 时,我的应用程序也应收到通知。
远足信使已经实现了与无障碍服务相同的功能。
我怎么解决这个问题 ?
提前致谢!!
我的语法可以在 android 5.1 上运行,但在 android 7.1 上不起作用......
File file = new File(Environment.getExternalStorageDirectory(), "Pictures/1481853170451.jpg");
Toast.makeText(MainActivity.this, file.getPath(), Toast.LENGTH_LONG).show();
Uri path = Uri.fromFile(file);
if (file.exists()) {
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(path, "image/*");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
this.startActivity(intent);
} catch (ActivityNotFoundException e) {
}
Run Code Online (Sandbox Code Playgroud)
谁能告诉我可能的答案。先感谢您....
android android-intent android-5.1.1-lollipop android-7.1-nougat