我想为Android创建一个进度条.我的方形进度条有四个图像.
我正在使用android定义的进度条:
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@android:style/Widget.ProgressBar.Small"
android:layout_marginRight="5dp" />
Run Code Online (Sandbox Code Playgroud)
但是,如果我想制作一个正方形而不是圆形,我该怎么办呢?如何将4张图像传递到进度条?
例:
我正在尝试String通过NFC发送,而我的应用程序正在使用屏幕固定.它不起作用:转移不会发生; 但如果我禁用屏幕固定工程的转移String.
我可以禁用屏幕固定一点,然后执行传输,但这是一个安全风险.
我怎样才能做到这一点?
如果您想尝试,这是所有代码.您需要做的就是通过应用程序设置手动启用屏幕固定(因此代码较少,但仍会产生相同的结果).我使用两个运行Android 5.0的Nexus 7测试了这个.
您不必阅读所有这些代码,如果您知道我可以添加到我的清单中的某些内容可以在屏幕固定时允许NFC,则可以解决此问题.
AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidnfc"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.NFC"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.androidnfc.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
MainActivity.java
public class MainActivity extends Activity implements CreateNdefMessageCallback, OnNdefPushCompleteCallback
{
TextView textInfo;
EditText textOut;
NfcAdapter nfcAdapter; …Run Code Online (Sandbox Code Playgroud) android nfc nfc-p2p android-5.0-lollipop android-screen-pinning
我正在推出这样的软键盘:
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInputFromWindow(buttonLayout.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
Run Code Online (Sandbox Code Playgroud)
buttonLayout是我的UI上的一个简单按钮.
如何提取用户写的内容(不使用EditText字段或隐藏EditText),以便用户无法看到或点击它?
我试图确保这两种方法是同步的。我注意到协程比线程更难同步。我怎么能保证如果我调用start()然后stop()我的代码实际上会在最后停止?
object Test {
private val coroutine = CoroutineScope(Dispatchers.IO)
@Synchronized
fun start() {
coroutine.launch {
// some work
}
}
@Synchronized
fun stop() {
coroutine.launch {
// clean up then stop
}
}
}
Run Code Online (Sandbox Code Playgroud)
我担心的是我start()当时打电话stop()但实际上先停止执行。所以我的代码在它应该停止的时候继续。
当我使用localhost在我的mac上运行时,我收到此错误.
需要具有FreeType支持的GD PHP扩展或支持PNG的ImageMagick PHP扩展.
我认为问题出在PNG图片上,默认情况下会在联系页面上呈现.所有代码都是Yii框架给出的基本代码:这里只有当我单击Contact导航栏上的选项卡时才会发生.
每次导航时,带有导航组件的底部导航视图都会重新创建片段。我想要一个 Singletop,我该怎么做?
我跟着这个教程:https : //proandroiddev.com/android-navigation-arch-component-a-curious-investigation-3e56e24126e1
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setupNavigation()
}
private fun setupNavigation() {
val navController = findNavController(R.id.mainNavigationFragment)
setupActionBarWithNavController(navController)
bottomNavigationView.setupWithNavController(navController)
}
override fun onSupportNavigateUp() =
findNavController(R.id.mainNavigationFragment).navigateUp()
}
Run Code Online (Sandbox Code Playgroud) 我试图在另一个挂起函数的参数中调用一个挂起函数。编译器实际上不允许这样做。它告诉我必须从挂起函数或协程调用挂起函数。
suspend fun compareElements(
isReady: Boolean = isReady() // IDE complains.
) {
...
}
//This is for this questions purpose. Reality is a bit more complex.
suspend fun isReady() = true
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?我需要isReady()在参数中。
我有两个协程,我想检查它们是否在同一上下文/调度程序中运行。这是我的问题的简化版本,但答案将适用于我正在做的事情:
@Test
fun test() {
val io = runBlocking(Dispatcher.IO) {
coroutineContext
}
val nonIo = runBlocking() {
coroutineContext
}
assertNotEquals(io, nonIo)
}
Run Code Online (Sandbox Code Playgroud)
然而,这是一个糟糕的测试,因为我只是比较两个不同的对象。我想比较一下他们用Dispatcher.IO还是不用。
我编辑了Apache,以便我的文档根目录在这里:
/var/www/html/Code/web/
Run Code Online (Sandbox Code Playgroud)
但现在我想指向文件~/Code/夹内的文件.
通常我可以使用:
include($_SERVER['DOCUMENT_ROOT'] . '/Controllers/MyFile.php');
Run Code Online (Sandbox Code Playgroud)
但这不适用于这个新文档的根目录.因此,在不更改文档根目录的情况下,如何指回此路径中的文件夹:
/var/www/html/Code/Controller/
Run Code Online (Sandbox Code Playgroud) myscript.command我正在尝试在 Mac/Linux 计算机上运行名为的脚本。
#!/bin/sh
echo 'Starting'
chmod 777 ./myfile
Run Code Online (Sandbox Code Playgroud)
问题是,当我到达该chmod部分时,我得到以下输出:
chmod ./myfile: No such file or directory
Run Code Online (Sandbox Code Playgroud)
但两者myscript.command都myfile在同一个文件夹中。
编辑
似乎当我启动脚本时,脚本的位置没有被保留。如何保留该位置?
通过在 UI 中双击来启动该脚本。