Kotlin开发AndroidStudio,IDEA配置/java转换Kotlin
来源:互联网 发布:点位图软件 brd 编辑:程序博客网 时间:2024/04/30 16:52
Kotlin维基百科地址:https://zh.wikipedia.org/wiki/Kotlin
百度百科:http://baike.baidu.com/view/9189237.htm
-Book链接 https://www.gitbook.com/book/huanglizhuo/kotlin-in-chinese/details
使用IDEA,或者Android Studio开发,配置
Setting ->Plugins->搜索[kotlin] 点击下载.等下完就行了,
或者直接去IDEA官网下载最新版本的IDEA自带Kotlin
将Java转成Kotlin
1.进入主方法MianActivity,
2.按住ctrl+shift+a,或者Code ->
3.在搜索框输入Convert Java File to Kotlin
github项目仓库地址:https://github.com/Servicehack/kotlin
源java代码:
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); }}
转换后的Kotlin代码;
class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val toolbar = findViewById(R.id.toolbar) as Toolbar setSupportActionBar(toolbar) val fab = findViewById(R.id.fab) as FloatingActionButton fab.setOnClickListener { view -> Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG).setAction("Action", null).show() } } override fun onCreateOptionsMenu(menu: Menu): Boolean { // Inflate the menu; this adds items to the action bar if it is present. menuInflater.inflate(R.menu.menu_main, menu) return true } override fun onOptionsItemSelected(item: MenuItem): Boolean { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. val id = item.itemId //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true } return super.onOptionsItemSelected(item) }}
1 0
- Kotlin开发AndroidStudio,IDEA配置/java转换Kotlin
- AndroidStudio配置使用Kotlin
- AndroidStudio配置Kotlin
- AndroidStudio 配置Kotlin
- androidstudio Kotlin环境(离线)配置
- androidstudio使用kotlin开发APP
- KotLin的简单使用 KotLin入门基础 AndroidStudio中配置KotLin插件 新建KotLin工程
- Kotlin配置开发Android
- Android开发Kotlin配置
- Kotlin语言学习之AndroidStudio集成Kotlin开发环境
- Kotlin在AndroidStudio上的配置
- Kotlin学习-AndroidStudio环境搭建与配置
- AndroidStudio安装kotlin插件及其配置过程
- 在AndroidStudio上搭建 Kotlin 开发环境
- java代码转换成 kotlin
- java代码转换成 kotlin
- Java?Kotlin?Kotlin!
- Java?Kotlin?Kotlin!
- css画空心箭头
- 求乘法逆元的三种写法
- Android开发之Android studio中的Theme Editor的简单使用
- USACO 2006 Mar SkiLift
- hdu5527 Too Rich(贪心)
- Kotlin开发AndroidStudio,IDEA配置/java转换Kotlin
- Windows环境jira 7.1.2安装破解
- pop到指定Controller的三个方法
- 宝马在华召回部分进口宝马M5和M6汽车
- PKCS1签名、PKCS7签名、PKCS数字信封
- application-specific permission settings do not grant Local Activation permission for the COM Server
- EasyDarwin开源流媒体服务器Work-stealing优化方案
- POJ 2975 Nim(博弈)
- linux搭建SVN服务器 (centos)