文档http://www.jetbrains.com/idea/help/rebuilding-project.html?search=reb只告诉我如何重建项目.
我不知道重建项目是什么意思(Menu --> Build --> Rebuild Project),它会清除所有编辑缓存吗?运行重建项目后,我发现项目的大小减少了吗?
在Android Studio中清除项目意味着什么?
我使用Android Studio编写我的App,下面的代码是我的布局文件,但有时Android Studio编辑器显示A.png并且有时显示B.png,这意味着有时系统会android:text="@string/myabout"用真正的字符串"About" 替换,但我不知道知道如何切换到用户界面.
而更多的,我怎么能更改的代码颜色android:text="@string/myabout"和android:text="Hard Code"?你知道File-> Settings - > Editor是巨树,我找不到我要编辑的项目.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/border_ui"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/myabout"
/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hard Code"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
A.png

B.png

在我使用eclipse创建Android应用程序之前,它可以在标题栏的左侧显示应用程序图标,请参阅图像aa.png.
现在我用Android Studio创建Android App,我已经将代码添加android:icon="@mipmap/ic_launcher"到manifest.xml文件中,但是app图标没有显示,请看图像bb.png,为什么?
顺便说compile 'com.android.support:appcompat-v7:22.1.1'一下compile 'com.android.support:appcompat-v7:18.0.0',如果我换了,可以显示图标,为什么?有没有com.android.support:appcompat-v7:22.1.1的错误?
aa.png

bb.png

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cuiwei.myapplication" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.cuiwei.myapplication"
minSdkVersion 9
targetSdkVersion 22
versionCode 1
versionName "1.0" …Run Code Online (Sandbox Code Playgroud) 以下代码来自https://kotlinlang.org/docs/reference/functions.html?q=&p=0
此代码计算余弦的固定点,这是一个数学常数.它只是从1.0开始重复调用Math.cos直到结果不再变化,结果为0.7390851332151607.
在我看来,我们无法比较两个浮点数是否相等,所以我认为结果if (x == y)总是假的,对吧?
private fun findFixPoint(): Double {
var x = 1.0
while (true) {
val y = Math.cos(x)
if (x == y) return y
x = y
}
}
Run Code Online (Sandbox Code Playgroud) 当我尝试构建项目1时,我收到以下错误.似乎gradle-3.0.0-beta6和gradle-3.0.0-beta9都不可用.
我在哪里可以找到android studio中最新的gradle版本?你能告诉我一个可以列出所有可用gradle版本的URL吗?
Error:Could not find com.android.tools.build:gradle:3.0.0-beta6.
Searched in the following locations:
file:/E:/Android_Studio_3.1/gradle/m2repository/com/android/tools/build/gradle/3.0.0-beta6/gradle-3.0.0-beta6.pom
file:/E:/Android_Studio_3.1/gradle/m2repository/com/android/tools/build/gradle/3.0.0-beta6/gradle-3.0.0-beta6.jar
https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0-beta6/gradle-3.0.0-beta6.pom
https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0-beta6/gradle-3.0.0-beta6.jar
Run Code Online (Sandbox Code Playgroud)
项目1
buildscript {
ext.support_version = '26.0.0'
ext.kotlin_version = '1.1.4-3'
ext.anko_version = '0.10.1'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:gradle-3.0.0-beta6'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}
Run Code Online (Sandbox Code Playgroud) 我创建了一个自定义Preference布局,并使用UIPreference.kt显示UI.
我可以简单地处理按钮btnCloseimport kotlinx.android.synthetic.main.layout_preference.*.
现在我希望简单地处理CheckBoxPreference chAutoRestore,但是布局是从xml\mypreference.xml加载的,我该怎么办?
目前,我必须使用该代码 val checkboxPref = preferenceManager.findPreference(getString(R.string.IsAutoRestore)) as CheckBoxPreference
UIPreference.kt
import kotlinx.android.synthetic.main.layout_preference.*
class UIPreference : AppCompatPreferenceActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.layout_preference)
fragmentManager.beginTransaction().replace(R.id.content, MyPreferenceFragment()).commit()
btnClose.setOnClickListener {
finish()
}
}
class MyPreferenceFragment : PreferenceFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
addPreferencesFromResource(R.xml.mypreference)
val checkboxPref = preferenceManager.findPreference(getString(R.string.IsAutoRestore)) as CheckBoxPreference
checkboxPref.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { preference, newValue ->
logError( "Pref " + preference.key + " changed to " + newValue.toString())
true
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
layout_preference.xml …
我使用代码A来设置WiFi的启用状态,当我在Android Studio 3.1.3中使用带有API 26和API 23的Android Emulator时,它运行良好,并且没有提示窗口!
但是我得到一个提示窗口"一个应用程序请求允许使用WLAN.允许吗?" 当我运行代码A时,在Android 5.1的真实手机中
如何让提示窗口不显示在真正的手机中?谢谢!
顺便说一句,真正的手机是搭载Android 5.1的三星SM-J5008
提示窗口
我已经设置了权限
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
Run Code Online (Sandbox Code Playgroud)
代码A.
fun setWiFi(aWiFiDef: WiFiDef): Unit{
val wifiManager =mContext.applicationContext.getSystemService(WIFI_SERVICE) as WifiManager
wifiManager.isWifiEnabled=aWiFiDef.status
}
Run Code Online (Sandbox Code Playgroud) 我在 Android Studio 3.3.1 中使用 Github。我知道我可以使用 Alt+9 打开版本控制。
并且 Git 命令和结果将显示在版本控制的控制台中。我可以输入 Git 命令并直接在 Android Studio IDE 中运行它吗?
以下代码来自项目架构-示例,您可以在此处查看。
我知道我可以使用诸如viewDataBinding.viewmodel访问布局控件或数据。
但是在下面的代码中,我发现val view = activity?.findViewById<View>(R.id.menu_filter) ?: return出现了,这是一个传统的代码。
有没有办法使用Databinding或Viewbinding技术访问选项菜单?
class TasksFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
viewDataBinding = TasksFragBinding.inflate(inflater, container, false).apply {
viewmodel = viewModel
}
setHasOptionsMenu(true)
return viewDataBinding.root
}
override fun onOptionsItemSelected(item: MenuItem) =
when (item.itemId) {
R.id.menu_clear -> {
viewModel.clearCompletedTasks()
true
}
R.id.menu_filter -> {
showFilteringPopUpMenu()
true
}
R.id.menu_refresh -> {
viewModel.loadTasks(true)
true
}
else -> false
} …Run Code Online (Sandbox Code Playgroud) 我在Android Studio中搜索文本,可以看到图像A
我发现搜索结果包含自动生成代码,例如LayoutHomeBindingImpl
我希望从自动生成代码中排除搜索结果,我该怎么办?
图片A
