小编Kyl*_*ner的帖子

Android P visibilityawareimagebutton.setVisibility只能从同一个库组中调用

我试图用新的Android P FloatingActionButton这部分com.google.android.material.floatingactionbutton.FloatingActionButton和我得到这样的警告:

VisibilityAwareImageButton.setVisibility只能从同一个库组中调用(groupId = com.google.android.material)

import com.google.android.material.floatingactionbutton.FloatingActionButton
import android.view.View

class MainActivity : AppCompatActivity() {

    lateinit var demoFab: FloatingActionButton

    override fun onCreate(savedInstanceState: Bundle?) {
        demoFab = findViewById(R.id.demoFab)
        demoFab.visibility = View.VISIBLE  // the warning is here
    }
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我尝试过搜索,唯一的搜索结果是关于响应UI可见性更改:

https://developer.android.com/training/system-ui/visibility

我试着探索如何VISIBLE在该com.google.android.material包中找到一个int值,并且我找到的唯一一个是com.google.android.material.floatingactionbutton.FloatingActionButton.VISIBLE,但警告仍然存在.

顶级build.gradle

buildscript {
    ext.kotlin_version = '1.2.41'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0-alpha14'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.google.gms:oss-licenses:0.9.2"
        // NOTE: Do not place your application dependencies here; they belong
        // in …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-jetpack android-9.0-pie

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

检测Webview错误和显示消息

我想在加载webview页面时出错(无连接)时显示错误消息.这是我到目前为止,没有错误处理代码:

public class TrackerPage extends Activity {

    // @Override
    private WebView webview;
    private ProgressDialog progressDialog;

    private boolean error;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Get rid of the android title bar
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        // Set the XML layout
        setContentView(R.layout.tracker_page);

        // Bundle objectbundle = this.getIntent().getExtras();
        webview = (WebView) findViewById(R.id.tracker);

        final Activity activity = this;

        // Enable JavaScript and lets the browser go back
        webview.getSettings().setJavaScriptEnabled(true);
        webview.canGoBack();

        webview.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }

            public …
Run Code Online (Sandbox Code Playgroud)

error-handling user-interface android webview

31
推荐指数
6
解决办法
8万
查看次数

对象数组的JSON模式定义

我已经看到了另一个问题,但它并不完全相同,我觉得我的问题更简单,但只是不起作用.

我的数据看起来像这样:

[
    { "loc": "a value 1", "toll" : null, "message" : "message is sometimes null"},
    { "loc": "a value 2", "toll" : "toll is sometimes null", "message" : null}
]
Run Code Online (Sandbox Code Playgroud)

我想在Node.js项目中使用AJV进行JSON验证,我尝试了几个模式来尝试描述我的数据,但我总是将其作为错误:

[ { keyword: 'type',
    dataPath: '',
    schemaPath: '#/type',
    params: { type: 'array' },
    message: 'should be array' } ]
Run Code Online (Sandbox Code Playgroud)

我试过的架构看起来像这样:

{
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "loc": {
        "type": "string"
      },
      "toll": {
        "type": "string"
      },
      "message": {
        "type": "string" …
Run Code Online (Sandbox Code Playgroud)

json jsonschema json-schema-validator

21
推荐指数
1
解决办法
4万
查看次数

javax.crypto.BadPaddingException

我正在研究AES算法,我有这个例外,我无法解决.

javax.crypto.BadPaddingException: Given final block not properly padded
at com.sun.crypto.provider.SunJCE_f.b(DashoA13*..)
at com.sun.crypto.provider.SunJCE_f.b(DashoA13*..)
at com.sun.crypto.provider.AESCipher.engineDoFinal(DashoA13*..)
at javax.crypto.Cipher.doFinal(DashoA13*..)
Run Code Online (Sandbox Code Playgroud)

异常发生在解密部分.我在与解密算法不同的地方初始化密钥

KeyGenerator kgen = KeyGenerator.getInstance("AES");//key generation for AES
kgen.init(128); // 192 and 256 bits may not be available
Run Code Online (Sandbox Code Playgroud)

然后我用我从文件中读取的密文传递给下面的方法

 public String decrypt(String message, SecretKey skey) {

    byte[] raw = skey.getEncoded();
    SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
    // Instantiate the cipher
    Cipher cipher;

    byte[] original = null;
    try {
        cipher = Cipher.getInstance("AES");

        cipher.init(Cipher.DECRYPT_MODE, skeySpec);
        System.out.println("Original string: "
                + message);
        original = cipher.doFinal(message.trim().getBytes());  //here where I …
Run Code Online (Sandbox Code Playgroud)

java encryption cryptography exception

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

处理器核心数与线程池大小的比较

很多时候我听说最好将线程池中的线程数保持在该系统中的核心数之下.拥有两个或更多线程而不是内核数量不仅是浪费,而且还可能导致性能下降.

那些是真的吗?如果没有,那些揭穿这些主张(特别是与java有关)的基本原则是什么?

java multithreading

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

在Android webview上,当我执行javascript时,sotfkeyboard消失

在WebView中,当我通过webview.loadUrl()执行JavaScript时,软键盘会在可见时消失.当我尝试在html文本字段中键入一些文本时,软键盘会消失(如果执行了JavaScript),我无法输入所有文本.

文本字段不会失去焦点,因此提示仍在文本字段中,但软键盘会关闭.

有人能告诉我如何解决这个问题?

javascript android focus webview android-softkeyboard

7
推荐指数
2
解决办法
931
查看次数

为什么我的facebook安卓sdk登录两次?

我正在使用Facebook SDK,问题是FormSubmit函数已经运行了两次.它是由被称为getView是通过调用函数onCreateView和由statusCallback,如何解决呢?

public class Home extends Fragment implements LoginListener {
    public View rootView;
    public ImageView HomeBg;
    public ImageView buttonLoginLogout;
    public TextView chi;
    public TextView eng;
    public ColorStateList oldColor;
    public SharedPreferences prefs;
    public EasyTracker tracker = null;

    //Facebook login
    private Session.StatusCallback statusCallback = new SessionStatusCallback();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        tracker = EasyTracker.getInstance(getActivity());
        prefs =  getActivity().getSharedPreferences("memberData", 0);

        getActivity().getActionBar().hide();

        rootView = inflater.inflate(R.layout.home, container, false);
        buttonLoginLogout = (ImageView) rootView.findViewById(R.id.home_connectFB);
        eng = (TextView) …
Run Code Online (Sandbox Code Playgroud)

android facebook callback android-fragments

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

删除日志文件中的^ L字符

我想删除我在阅读文件时找到的所有字符"\ L".我在读一行时尝试使用此功能:

def cleanString(self, s):
            if isinstance(s, str):
                    s = unicode(s,"iso-8859-1","replace")
                    s=unicodedata.normalize('NFD', s)
                    return s.encode('ascii', 'ignore')
Run Code Online (Sandbox Code Playgroud)

但它不会删除此字符.有人知道怎么做吗?

我也试过使用这个replace功能,但它并不是更好:

s = line.replace("\^L","")
Run Code Online (Sandbox Code Playgroud)

谢谢你的回答.

python unicode

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

ActionBar选项卡带有支持库

我遇到的问题是Action Bar不会在Android 2.3.7上显示,但在4.x +上可以正常工作.我的应用程序的其余部分与支持v7和v4库工作正常,只是这一个区域给我带来了麻烦.

这是它应该是什么样子,如4.3所示:

Android 4.3查看

以下是2.3.7的内容:

Android 2.3.7视图

在我的onCreate方法(继承自ActionBarActivity的类)中,我有:

    // setup action bar for tabs
    ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);


    Tab tab = actionBar.newTab()
            .setText(R.string.details)
            .setTabListener(new TabListener<DetailsFragmentOne>(
                    this, "one", DetailsFragmentOne.class));
    actionBar.addTab(tab);

    tab = actionBar.newTab()
        .setText(R.string.grades)
        .setTabListener(new TabListener<DetailsFragmentTwo>(
                this, "one", DetailsFragmentTwo.class));
    actionBar.addTab(tab);
Run Code Online (Sandbox Code Playgroud)

这是我的TabListener,一个内部类:

/**
 * This is copied almost verbatim from <a href="http://developer.android.com/guide/topics/ui/actionbar.html#Tabs">the ActionBar Tabs API Guide</a>.
 * @param <T>
 */
public class TabListener<T extends Fragment> implements ActionBar.TabListener {
    private Fragment mFragment;
    private final Activity mActivity;
    private final String mTag;
    private …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-support-library

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

使用Thread获取图像资源时,Intent选择器保持打开状态

我正在构建一个照片上传表单,该表单必须从相机或图库或任何其他可用资源(Dropbox/Google Drive/Astro文件管理器等)获取图像.我认为除了一个小组件外我都能正常工作.

当所选图像来自网络资源(例如Google云端硬盘)时,可能需要很长时间才能返回活动.我想使这个异步,以避免用户在图像下载时盯着黑屏.

我写了很多代码来完成整个工作,但这是它的一般过程:

  1. 活动开始并显示表单.

  2. Intent选择器自动打开并要求用户从相机或其他应用程序中选择图像.

  3. 用户选择某些应用程序(如Google云端硬盘),选择图像并关闭该应用,然后返回所选图像Uri作为结果.

  4. 缓存文件的内容以解决方法KitKat权限,如果活动关闭并需要恢复,则可以阻止重新读取图像.

  5. 使用缓存文件作为源异步显示缩放位图.

  6. Intent选择器关闭,图像显示在ImageButton中,并且表单对用户可见,在提交之前填写.

  7. 点击提交按钮后,将启动异步任务,允许将多部分上载到服务器.

  8. 异步上载使用回调函数来通知用户上载进度.

我陷入了#3和#4之间的过渡期.

如果我使用Thread或AsyncTask Intent选择器将保持打开状态,但图像也将显示在表单上.

如果我只是强迫用户等待(连续) 用户被卡住看黑屏,则意图选择器关闭,图像显示在表单上.

打开Intent选择器

/**
 * see http://stackoverflow.com/a/12347567/940217
 */
private void openImageIntent() {

    // Camera.
    final List<Intent> cameraIntents = new ArrayList<Intent>();
    final PackageManager packageManager = getPackageManager();
    Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

    File photoFile;
    try {
        uploadableImage.makeCameraTempFile();
        photoFile = uploadableImage.getCameraTempFile();
        uploadableImage.setCameraFilepath(photoFile.getAbsolutePath());
    } catch (IOException ex) {
        // Error occurred while creating the File
        photoFile = null;
        uploadableImage.invalidate();
        Log.e(TAG, "Error while creating the temporary file needed …
Run Code Online (Sandbox Code Playgroud)

android android-asynctask

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