如何制作父布局 -Box将其内容包装在 Jetpack compose 中?下面当前的实现填充了整个屏幕,我只想Box环绕它的子项 - Switch。如何定义 的换行内容Box?
@Composable
fun TestScreen(modifier: Modifier = Modifier) {
Box(modifier = Modifier.background(Color.Yellow)){
val switchState = remember { mutableStateOf(true) }
Switch(
checked = switchState.value,
enabled= true,
onCheckedChange = { switchState.value = it }
)
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法UITableView在swift中获得每行的行高?请帮忙.提前致谢.
我需要从我在字符串中获得的文件名来决定文件的文件类型.所以我决定获取String的最后三个字符来决定它是什么文件类型.如何获取String中的最后三个字符.例如
var fileName = "test.pdf"
Run Code Online (Sandbox Code Playgroud)
我需要单独获取pdf.有没有其他更好的方法来检查除此之外的文件类型.请建议我.因为我认为,我能够识别文件类型是否有四个字符,如"jpeg"和其他东西.提前致谢.
如何从服务器的响应中获取id,content,name的值.来自服务器的响应是AnyObject,如果我打印,它看起来如下所示......
{
content = xxxx
id = 22
name = yyyy
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我正在使用解析来注册用户并登录。我已经成功完成了这些模块。现在我的疑问是,我在哪里以及如何检查用户是否已经登录。如果用户已经登录,向他展示 MainActivity 否则向他展示 HomeActivity。
目前我有 HomeActivity 作为我的启动器 Manifest
<activity
android:name=".Activities.Home"
android:label="@string/title_activity_home" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
然后我有一个 Application 类,我在其中初始化解析对象。
public class MyClass extends Application {
public static Context context;
@Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
Parse.initialize(this, "KEYS", "KEYS");
if(ParseUser.getCurrentUser().isAuthenticated()){
Intent intent = new Intent(context,MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}else{
Intent intent = new Intent(context,Home.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在 logcat 中收到此错误
java.lang.RuntimeException: Unable to create application com.artqueen.aahaan.Aahaan: java.lang.NullPointerException: Attempt to invoke virtual method …Run Code Online (Sandbox Code Playgroud) 我正在使用具有标题布局的NavigationView,该标题布局包含我试图在我的Activity中访问的textview,它返回null.
试着花很多时间在上面,没有希望.
我的活动
public class MainActivity extends AppCompatActivity {
private DrawerLayout mDrawerLayout;
RelativeLayout headerLL;
ImageView userIV;
TextView usernameTV;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
headerLL = (RelativeLayout) findViewById(R.id.navHeaderLL);
userIV = (ImageView) findViewById(R.id.userDPIV);
usernameTV = (TextView) findViewById(R.id.usernameTV);
//getting error here
usernameTV.setText("Ashiq");
initializeDrawer();
}
}
Run Code Online (Sandbox Code Playgroud)
activity_mail.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<include layout="@layout/include_list_viewpager"/>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header"
app:menu="@menu/drawer_view"
/>
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
nav_header.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="192dp"
xmlns:tools="http://schemas.android.com/tools"
android:background="?attr/colorPrimaryDark" …Run Code Online (Sandbox Code Playgroud) 我试图访问如果用户是否登录,基于我尝试启动应用程序的活动.执行此操作时,应用程序在Application类中崩溃.
应用程序类的代码是
public class MyClass extends Application {
public static Context context;
@Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
if(ParseUser.getCurrentUser().isAuthenticated()){
startActivity(new Intent(context, MainActivity.class));
}
}
}
Run Code Online (Sandbox Code Playgroud)
有什么建议为什么会这样?
在我的Manifest中,我已经为另一个活动声明了intent过滤器.
<activity
android:name=".Activities.Register"
android:label="@string/title_activity_register" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud) 我有一个MainActivity,它包含一个Sliding抽屉菜单和一个FragmentContainer来切换片段.
我有一个名为History的片段,它有这样的布局
<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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<com.astuetz.PagerSlidingTabStrip
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@color/colorPrimary"
android:textColor="#FFFFFF"
app:pstsIndicatorColor="#FFFFFF" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/tabs" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这堂课看起来像这样
public class HistoryFragment extends Fragment {
public HistoryFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_history, container, false);
// Initialize the ViewPager and set an adapter
ViewPager …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的应用添加facebook登录.我正在使用带有自己的按钮的FBSDKLoginButton,一旦你登录它就会转向注销.我不想要那一切.我只需要添加自己的按钮视图.在那个按钮的@IBAction中我想要登录facebook.我现在使用的代码是
class ViewController: UIViewController,FBSDKLoginButtonDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
if (FBSDKAccessToken.currentAccessToken() != nil)
{
// User is already logged in, do work such as go to next view controller.
}
else
{
let loginView : FBSDKLoginButton = FBSDKLoginButton()
self.view.addSubview(loginView)
loginView.center = self.view.center
loginView.readPermissions = ["public_profile", "email", "user_friends"]
loginView.delegate = self
}
}
func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
println("User Logged In")
if ((error) …Run Code Online (Sandbox Code Playgroud) 我用a UILabel来包含一些文字.此文字有时可能包含一些链接,例如http://www.google.com或www.google.com,甚至google.com.如何检测这些链接并使文本可单击以在浏览器中打开.请指教.提前致谢.
我试图用数位来自Twitter的.该AuthCallBack从活动中使用和最近时不会触发文件说,从使用AuthCallBack 应用类.
现在我让AuthCallBack正常工作并且onSuccess我需要从我的MainActivity调用一个方法.我如何从Application类实现它.请帮助.我已经给出了下面的代码.
public class MyApplication extends Application {
private AuthCallback authCallback;
@Override
public void onCreate() {
super.onCreate();
authCallback = new AuthCallback() {
@Override
public void success(DigitsSession session, String phoneNumber) {
//call myFunction() from MainActivity here
}
@Override
public void failure(DigitsException exception) {
}
};
}
public AuthCallback getAuthCallback(){
return authCallback;
}
}
Run Code Online (Sandbox Code Playgroud) android twitter-oauth twitter-digits android-application-class
我正在使用a RecyclerView,当我触摸该项目时,我无法看到任何反馈RecyclerView.我该如何实现?
我试图在用户触摸行时向用户显示反馈RecyclerView.像涟漪效应的东西.
我想知道如何在特定的一行中实现它RecyclerView.
这是回收站视图的自定义行布局.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/drawer_row"
android:background="?android:attr/selectableItemBackground"
android:clickable="true">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"
android:layout_toEndOf="@+id/navigation_image"
android:layout_toRightOf="@+id/navigation_image"
android:textSize="17sp" />
<ImageView
android:id="@+id/navigation_image"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp" />
<TextView
android:id="@+id/horizontal_line"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
android:background="#F1F1F1" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这是的布局Activity具有RecyclerView
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/windowBackground">
<RelativeLayout
android:id="@+id/nav_header_container"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:background="@drawable/ic_drawer_header">
<ImageView
android:id="@+id/circle_imageview"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="@drawable/profile_pic"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content" …Run Code Online (Sandbox Code Playgroud)